Sign in to follow this  

Detecting Application Data Directory

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a program in Windows in the System32 folder that I can call that returns the Application Data directory, or how should I go about making the program determine where to store Application Data? It is different for many versions of Windows, and with there being more versions of Windows coming up in the future, I cannot just make an array with possible directories because I would need to update that with each Windows release. Please give an informative example of how to detect exactly there the Application Data is to be stored. Thank you. :)

Share this post


Link to post
Share on other sites
I believe the environment variable [font=courier new,courier,monospace]%APPDATA%[/font] is set for all reasonable versions of Windows you may be targeting (from Windows 2K and up, I believe). So something like [font=courier new,courier,monospace]filepath = "%APPDATA%\\folder\\file.txt";[/font]

You shouldn't need to call a program. But if you do [font=courier new,courier,monospace]Start -> Run... -> %APPDATA%[/font] it should pop up an Explorer window with the appropriate folder open, if you're curious. Edited by Cornstalks

Share this post


Link to post
Share on other sites
Thank you for this tip. I tried this and it printed %APPDATA% just the same, however, so there must be more to it than this. Also, creating the directory will need to be done by the installer I create, correct?

Share this post


Link to post
Share on other sites
Although it's C++, perhaps it will be of some use: [url="http://stackoverflow.com/questions/2899013/how-do-i-get-the-application-data-path-in-windows-using-c"]http://stackoverflow...windows-using-c[/url]

If you have access to the registry, you can read HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\AppData, as documented here: [url="http://technet.microsoft.com/en-us/library/cc962614.aspx"]http://technet.micro...y/cc962614.aspx[/url] Edited by Matt-D

Share this post


Link to post
Share on other sites
SHGetKnownFolderPath appears to be the current official way of doing this: [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb762188%28v=vs.85%29.aspx"]http://msdn.microsof...8(v=vs.85).aspx[/url]

If you're creating an installer I'd highly recommend that you use a well-known installer technology rather than trying to roll your own. Visual Studio, for example, can be used to create an MSI file, and it will resolve all of this for you, as well as provide for uninstallation (and also be compatible with remote deployment via e.g. Group Policy). Edited by mhagain

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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