Where to save preferences file on Windows?

Started by
8 comments, last by theequal 14 years, 9 months ago
Hello, my app creates and saves my preferences file in it's own folder, however I go a few reports of the application not creating the preferences file in Vista (only for some people). Could you guess why? Is having the preferences file in the local folder not recommended? Where should I save them instead? (I prefer not to touch the registry) Thanks, Matteo
Advertisement
#include <shlobj.h>char P[MAX_PATH];SHGetFolderPath(NULL,CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE,NULL,0,P);


SHGetFolderPath.

This is the correct place to create a folder to store local application data. Your application can write there without special privileges and it will respect multiple user accounts correctly.

Bear in mind though if you do this that it is polite to include an uninstaller for your application that removes your folder and its contents from this directory. It was actually when I started doing the above that I finally gave up distributing things in ZIP files and learned NSIS.
Quote:Original post by Ragdollsoft
Hello, my app creates and saves my preferences file in it's own folder, however I go a few reports of the application not creating the preferences file in Vista (only for some people). Could you guess why?



the person playing the game is not logged in as an administrator, or User Access Control is enabled. google it. realize that you would have to convince the user to run your game as an administrator. let them tell you they are not retarded. then store your preferences where Aardvajk said to.

Quote:Original post by Aardvajk
Bear in mind though if you do this that it is polite to include an uninstaller for your application that removes your folder and its contents from this directory. It was actually when I started doing the above that I finally gave up distributing things in ZIP files and learned NSIS.
NSIS doesn't exactly work correctly either; it insists on creating shortcuts in the current user's start menu, even if you pick an existing start menu folder in the all users/public profile. As one of those people who are very particular about the layout of their start menu I'd always recommend Inno Setup instead. [wink]

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

Quote:Original post by benryves
Quote:Original post by Aardvajk
Bear in mind though if you do this that it is polite to include an uninstaller for your application that removes your folder and its contents from this directory. It was actually when I started doing the above that I finally gave up distributing things in ZIP files and learned NSIS.
NSIS doesn't exactly work correctly either; it insists on creating shortcuts in the current user's start menu, even if you pick an existing start menu folder in the all users/public profile. As one of those people who are very particular about the layout of their start menu I'd always recommend Inno Setup instead. [wink]


I'd noticed some other weirdness actually where I installed into a custom start menu folder which broke the uninstaller.

I'll have to have a look at Inno. I think you've told me this before as I recall. Damnit, all that time invested in running Isis Edit and clicking through a wizard [smile].

Enough thread-jacking...
Works nicely, thanks.

The docs say SHGetFolderPath is deprecated but I guess it's the easiest way to get a solution working for both XP and Vista.
Quote:Original post by Ragdollsoft
The docs say SHGetFolderPath is deprecated but I guess it's the easiest way to get a solution working for both XP and Vista.
MSDN doesn't actually say that it is deprecated, merely that Vista-only applications should use the newer function. I certainly wouldn't expect it to be removed from a future version of Windows.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

What part of "Deprecated" doesn't actually say that it's deprecated :P
Microsoft's bread and butter is compatibility. That's why DOS games still work (on 32-bit systems anyway). They essentially never actually remove functionality. "Deprecated" in MSDN is actually thier way of saying "we really wish the world would do something else rather than keep using this stale cruft which we'd like to get rid of but can't because it would break some crappy LOB app and we would lose 10,000 units of sales for the next version".
-Mike
Quote:Original post by Ragdollsoft
Hello, my app creates and saves my preferences file in it's own folder, however I go a few reports of the application not creating the preferences file in Vista (only for some people). Could you guess why?

Is having the preferences file in the local folder not recommended? Where should I save them instead? (I prefer not to touch the registry)

Thanks,

Matteo


If they can't find it, then they're probably looking in the wrong place.

Under Vista, the program directory is protected. Apps can't write to it. Instead, the re-route everything to a VirtualStore directory, like:
C:\Users\<User_name>\AppData\Local\VirtualStore\Program Files\MyApp

This is totally transparent to the app, so your app may think its writing to C:\Program Files\MyApp, but it's actually somewhere else.

They do the same thing with registry keys too. Everything gets stored under a VirtualStore key directory, at least for those apps who try to write in protected areas.

This topic is closed to new replies.

Advertisement