I want to get the path to the Desktop from the registry, but it returns %SRRFL%DstpE%\Desktop
even though the value in registry is set to %USERPROFILE%\Desktop
. Why does this happen?
Here is my code:
string desktop_path;
HKEY hKey;
LONG error = RegOpenKeyExA(
HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
NULL,
KEY_WOW64_64KEY | KEY_QUERY_VALUE,
&hKey
);
if (error == ERROR_SUCCESS) {
wchar_t buffer[MAX_PATH];
DWORD bufferSize = MAX_PATH;
LONG result = RegQueryValueExA(
hKey,
"Desktop",
NULL,
NULL,
(LPBYTE)&buffer,
&bufferSize);
if (result == ERROR_SUCCESS) {
wstring ws(buffer);
string str(ws.begin(), ws.end());
cout << "The reg key is: " << str<< endl;
desktop_path = str;
}
}