Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello I have to write a C++ program to save user setting
Use is not admin rights and can not save in install folder
What is correct place to save data

What I have tried:

I try to save to temp folder but data get deleeted random times
How to stop deleting data?
Posted
Updated 23-Jul-16 2:08am
Comments
Garth J Lancaster 23-Jul-16 7:19am    
impossible to answer given you dont show any code nor expound in which version of windows you're using, nor outline any other variables - etc virus checkers etc ....

1 solution

Windows provides special folders for such data. The folder to be used depends on the type of the data (user specific or app specific).

Use the SHGetKnownFolderPath function (Windows)[^] to get the path for such folders and append the name of your application. Before storing data the first time you must create the folder.

Depending on your type of data, these folder IDs may be used (see KNOWNFOLDERID (Windows)[^] for a complete list):

Per user (not accessible by other users)

FOLDERID_Documents (%USERPROFILE%\Documents)
For personal documents created by your application.

FOLDERID_LocalAppData (%USERPROFILE%\AppData\Local)
For user specific application data (e.g. settings).

FOLDERID_RoamingAppData (%USERPROFILE%\AppData\Roaming)
As above but for domain login accounts (data shared when logged in on multiple systems).

For all users

FOLDERID_ProgramData
For system wide application data.

FOLDERID_PublicDocuments
For public (shared) documents created by your application.
 
Share this answer
 
Comments
bhavya-hyd 24-Jul-16 5:05am    
Thank you, I think I have to use AppData/Local or Roaming but I don't know user is domain or not domain. Which one is correct if I don't know?
Jochen Arndt 24-Jul-16 5:31am    
I don't know the type of your application, what is stored, and how it might be used. So it is difficult to answer. Domain means that the user is working in a corporate network where he logs in using a NT domain service. When roaming profiles are enabled, the roaming folder is redirected to a folder on the server. This works behind the scenes.

An example where using the roaming folder makes no sense are settings storing the application's window size. When then working on a system with a small screen, settings for a wide screen are invalid.

For such circumstances you have to use both folders: The local one for system dependant settings and the roaming folder for system independant but application specific settings.

If your users are mainly working local (private or using Windows Home versions), use the local folder. Supporting roaming profiles is a convenience option that might be expected for professional software but is not always required (again: it depends on the type of data/settings that are stored).
bhavya-hyd 26-Jul-16 9:07am    
Thank you your answers is very helpful. I think I can use local profile because I think nobody use roaming profile. I can't tell what my program is doing because boss forbid telling about details

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900