# Where to save preferences file on Windows?

This topic is 3343 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
#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.

##### Share on other sites
Quote:
 Original post by RagdollsoftHello, 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.

##### Share on other sites
Quote:
 Original post by AardvajkBear 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]

##### Share on other sites
Quote:
Original post by benryves
Quote:
 Original post by AardvajkBear 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].

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by RagdollsoftThe 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.

##### Share on other sites
What part of "Deprecated" doesn't actually say that it's deprecated :P

##### Share on other sites
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".

##### Share on other sites
Quote:
 Original post by RagdollsoftHello, 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.

1. 1
2. 2
3. 3
Rutin
20
4. 4
frob
18
5. 5

• 32
• 13
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
632561
• Total Posts
3007088

×