Recommended solution to an application to allow an application to have settings files that can be shared by multiple users of the same machine

StackOverflow https://stackoverflow.com/questions/20800262

Question

I'm currently working on a project where my application generates some setting files (inside the programfiles(x86) folder) that is further used by a different application. Now, I want even the non-administrative users of my software to use this functionality of generating the setting files in the programfiles(x86) folder. I'm using C++ to create my application.

So, do we have a functionality in c++ such that even the non-administrators can create a setting file in the ProgramFiles(x86) folder.

What is Microsoft's way of handling such situations?

Can someone please guide me with a good solution to this problem.

Thanks in advance.

Was it helpful?

Solution

Per-machine configuration data should be stored in a sub-folder of the location referenced by FOLDERID_ProgramData.

The location can change depending on what OS version you are using. It can also be localized (folder names that vary depending on the system language). It can also be changed by the system administrator.

Therefore, it’s very important that you do not hard-code the folder name into your app. Instead, you use the Known Folders APIs. Call SHGetKnownFolderPath, passing one of the KNOWNFOLDERID values.

This MSDN blog post explains which Known Folders to use in various scenarios.

PWSTR path = nullptr;
HRESULT hr = SHGetKnownFolderPath(FOLDERID_ProgramData, 0, NULL, &path);
if (FAILED(hr)) {
    // error handling
}

// use the path

// when you are done, you must free the memory yourself:
CoTaskMemFree(path);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top