views:

184

answers:

2

I looked all over the internet and there doesn't seem to be a decent solution that I could find. I want to be able to programmatically in C++ obtain the path "%ALLUSERSPROFILE%\Application Data" that explorer can translate into a real path.

Can I do this without relying on third-party code?

+8  A: 

Use SHGetFolderPath with CSIDL_COMMON_APPDATA as the CSIDL.

TCHAR szPath[MAX_PATH];
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, szPath)))
{
    //....
}
interjay
Nice, CSIDL_COMMON_APPDATA IS the CSIDL I'm looking for.
Brian T Hannan
There is also the newer, and not necessarily spiffier, SHGetKnownFolderPath. Available on Vista or later.
OldFart
A: 

you can also read the value from the registry

path = HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders

key = Common AppData

Remus Rigo
Do-able I suppose.
Brian T Hannan
Undocumented and subject to change; avoid it. There's the API, use it.
Matteo Italia