Sign in to follow this  
floatingwoods

about programmatically writing to the windows system folder

Recommended Posts

Hi, I'd like to put a simple text file (i.e. non-executable file) into a computer's Windows system folder in order for my application to store some basic information that won't be removed when desinstalling the application (e.g. if the user re-installs the application or a newer version of it, the same settings can be re-used). Is this bad practice? I know most would use the registry for that, but I prefer not because: 1. It seems you need administrator priviledges to write to the registry and my user might not be administrator. 2. There is quite a bit of data, that would be quite troublesome to put it all into the registry. How would I do this? Is there a simple function that gives me the path to the system folder? Will I also need administrator priviledges there? Thanks!

Share this post


Link to post
Share on other sites
I don't think I would use the system folder unless it was a dll or executable that was supposed to be shared among applications.
Anyway, if you are using C++ you can try the GetSystemDirectory function, or if you are using C#, Environment.SystemDirectory

Another option is to save the application speciffic files in the Program Files directory, and add a registry key to that folder.

Share this post


Link to post
Share on other sites
Quote:
Original post by floatingwoods
1. It seems you need administrator priviledges to write to the registry and my user might not be administrator.
You need to be an administrator to write to the HKEY_LOCAL_MACHINE hive, but any user can write to their own HKEY_CURRENT_USER hive. Also, you need to be an administrator to write to the system folder (assuming you mean Windows\System32 or whatever).

You can write to somewhere under CSIDL_COMMON_APPDATA if you want to go that route.

Share this post


Link to post
Share on other sites
Quote:
Original post by floatingwoods
... that won't be removed when desinstalling the application... Is this bad practice?


Yes. When I uninstall something, I want it gone. Or at least have the option to make it gone. If you have a little check box I can click to keep save games and whatnot, that's OK, but you've really got to be able to remove everything in your uninstaller.

Share this post


Link to post
Share on other sites
Quote:
Original post by floatingwoods
Is this bad practice?

Yes. Unless you are writing a device driver, or some windows kernel component.

Quote:
How would I do this? Is there a simple function that gives me the path to the system folder? Will I also need administrator priviledges there?


Your application is given several locations into which you may put anything:
- The installation location (may not be /Program Files)
- The appropriate Documents&Settings or Users directory
- The temp directory

The APPDATA location mentioned above seems like best choice if you wish to store something that is intended for every user.

Quote:
I don't think I would use the system folder unless it was a dll or executable that was supposed to be shared among applications.


Even then, with 32/64-bit and XP/Vista/7 differences, as well as SxS mappings, there simply is no real reason to write there manually.

And security under Vista and 7 has gotten much tighter, with more users running as non-admin accounts, meaning that trying to modify anything outside of previously provided locations can cause problems.


For example, on my installations, I don't use default locations, so I keep program files on D, profiles and my documents on another drive, temp is on ram drive, etc... I really notice misbehaving applications since they seemingly litter all over the disk.

Quote:
f the user re-installs the application or a newer version of it


To upgrade, the installer offers an option to install into same location as existing version. If they uninstall it, then they want to get rid of it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Antheus
Your application is given several locations into which you may put anything:
- The installation location (may not be /Program Files)
Assuming the installation directory is inside Program Files, then you may not put "anything" there unless you give the application administrator privileges. Vista acknowledges that sloppy programmers may stick data in Program Files and so will end up dumping the files into %userprofile%\AppData\Local\VirtualStore\Program Files instead.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this