My app needs to install some files that can be edited by the application at run time. Install shield provides an alias [CommonAppDataFolder] that will resolve to c:\programData on Vista and Windows 7 and will also work on Windows XP. Is there a win32 function that will return a similar path?
Maybe I need to call different functions depending on the operating system?
To view the "ProgramData" folder you will need to go to the Windows control panel , select "Appearance and Personalization", and find the "folder options" dialog. Select the View Tab, make the changes shown above, and click OK. You should now be able to see and access the "ProgramData" folder.
On Windows XP, there was no C:\ProgramData folder. Instead, there was a “C:\Documents and Settings\All Users\Application Data” folder. Starting with Windows Vista, the All Users application data folder was moved to C:\ProgramData. You can still see this today.
The known folder system that underlies SHGetFolderPath allows users or administrators to redirect a known folder to a location that suits their needs.
SHGetFolderPath
/SHGetSpecialFolderPath
get you that, with CSIDL_COMMON_APPDATA
argument.
See code snippet here (at the bottom): How to write a Windows XP Application that stores user and application data in the correct location by using Visual C++ ; the original link is no longer valid - code snippet is pulled below):
include <shlwapi.h>
#pragma comment(lib,"shlwapi.lib")
void CreateTemporaryFile()
{
TCHAR szPath[MAX_PATH];
// Get path for each computer, non-user specific and non-roaming data.
if ( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_COMMON_APPDATA,
NULL, 0, szPath ) ) )
{
TCHAR szTempFileName[MAX_PATH];
// Append product-specific path - this path needs to already exist
// for GetTempFileName to succeed.
PathAppend( szPath, _T("\\My Company\\My Product\\1.0\\") );
// Generate a temporary file name within this folder.
if (GetTempFileName( szPath,
_T("PRE"),
0,
szTempFileName ) != 0 )
{
HANDLE hFile = NULL;
// Open the file.
if (( hFile = CreateFile( szTempFileName,
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL )) != INVALID_HANDLE_VALUE )
{
// Write temporary data (code omitted).
CloseHandle( hFile );
}
}
else
DWORD err = GetLastError();
}
}
See also: CSIDL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With