Re: How to modify program files in Vista?
- From: Daniel James <wastebasket@xxxxxxxxxxxxxxxx>
- Date: Thu, 07 Aug 2008 08:26:02 +0100
In article news:<r6ji94tr0re9n1i9buetvsd8os9tu6pld6@xxxxxxx>, Joseph M.
Newcomer wrote:
Your use of a .INI file which is kept in the same directory as your
executable is incorrect usage. You must change your program to store
information in the My Documents or AppData; ...
True ... but it is actually quite common for (older) applications to
store an INI file in the application directory, and MS don't really give
sensible guidelines on dealing with the problem.
If there is an application ini file that is common to all users there
isn't really any provision to store that file in the prescribed Windows
file hierarchy.
What Microsoft would like developers to do is to store the configuration
not in an INI file but in the registry. If the information is system-wide
information (not per-user) it has to be stored in the HKLM hive ... which
is not normally writable by non-Admin users, so the problem persists.
Even if you stick to writing the information to an INI file there is
nowhere in the file hierarchy to store globally writable configuration
data. The obvious place would be the all users profile directory ... but
that's not writable by normal users. Users can, of course, write into
their own profile directories but those are user-specific and not
accessible by other users.
So, my advice to the OP would be:
1. See whether your application can be rewritten so that global
configuration infomation does not need to be written by all users -- you
may perhaps be able to set up a global set of default configuration that
all users will use the first time they run the program, and a set of
personal configuration files (one per user) in which the users save their
own configurations. These personal configuration files can be placed in a
subdirectory of the user's user profile folder.
It may be that this doesn't make sense for your program -- the global
configuration might contain a sequence number that is supposed to be
incremented for every operation carried out, regardless of who did it,
for example -- in which case you really do need to have a common
configuration file.
You then have some other options:
2. Place your INI file in the program directory, as you do at present,
but change your installation program so that it grants write access to
the INI file (ONLY the INI file) to all users. This goes against the
programming guidelines that say that everything in "Program Files" should
be read-only, but it's pragmatic and it usually works. Note that it won't
work if your program deletes the old INI file and creates a new one when
it writes ... the new file won't get the altered permissions.
3. Create an application data folder in the all users profile folder and
write your INI file there. You will have to change the permissions on
this folder so that it can be written by normal users (but that's less
potentially risky than changing permissions in the Program Files
directory.
4. Use the registry. Create a suitable key in the HKLM hive for your
application and change the permissions on it so that all users can write
to it.
Note that pretty-much whatever you do you will have to change the
permissions on the file or folder or hive that you create. This is
because Microsoft hasn't provided any place within their recommended file
structure to put public mutable data.
The other possibility (5) is simply to ignore Microsoft's prescribed
directory structure and install your application in a directory that is
not part of the Program Files directory -- e.g. C:\MyApp. Such a
directory will be writable by all users by default and you can put what
you like there.
Note that one important benefit of protecting program files fro writing
is that it makes it very difficult for viruses, etc, to alter them when
the system is being used (by a non-Administrator ... that's why you
should never use an Administrator account unless you really have to). If
you install your application in its own directory outside the Program
Files hierarchy you will not get this benefit by default.
Note that when I talk about directories such as "the program files
directory" or the "All Users directory" I mean the directories returned
by the shell SHGetFolderPath API (or shGetKnownFolderPath if you want
your application only to work on Vista -- I'd advise against that). It is
important always to use these APIs to get the pathnames because Vista
uses different paths from XP and Win2k, and because some of the folders
have different names in non-English-language versions of Windows.
Cheers,
Daniel.
.
- Follow-Ups:
- Re: How to modify program files in Vista?
- From: Joseph M . Newcomer
- Re: How to modify program files in Vista?
- References:
- How to modify program files in Vista?
- From: fiveight
- Re: How to modify program files in Vista?
- From: Joseph M . Newcomer
- How to modify program files in Vista?
- Prev by Date: Re: Win32 DLL def file question
- Next by Date: Re: How to handle blank date and time?
- Previous by thread: Re: How to modify program files in Vista?
- Next by thread: Re: How to modify program files in Vista?
- Index(es):
Relevant Pages
|