- hr = _SHGetUserShellFolderPath(hRootKey, userPrefix,
- CSIDL_Data[folder].szValueName, pszPath);
+ userPrefix = NULL;
+ }
+ else
+ {
+ /* Get the folder of the specified user */
+ DWORD InfoLength;
+ PTOKEN_USER UserInfo;
+
+ hRootKey = HKEY_USERS;
+
+ GetTokenInformation(hToken, TokenUser, NULL, 0, &InfoLength);
+ UserInfo = (PTOKEN_USER)HeapAlloc(GetProcessHeap(), 0, InfoLength);
+
+ if(!GetTokenInformation(hToken, TokenUser, UserInfo, InfoLength, &InfoLength))
+ {
+ WARN("GetTokenInformation failed for %x!\n", hToken);
+ HeapFree(GetProcessHeap(), 0, UserInfo);
+ return E_FAIL;
+ }
+
+ if(!ConvertSidToStringSidW(UserInfo->User.Sid, &userPrefix))
+ {
+ WARN("ConvertSidToStringSidW failed for %x!\n", hToken);
+ HeapFree(GetProcessHeap(), 0, UserInfo);
+ return E_FAIL;
+ }
+
+ HeapFree(GetProcessHeap(), 0, UserInfo);
+ }
+
+ hr = _SHGetUserShellFolderPath(hRootKey, userPrefix, CSIDL_Data[folder].szValueName, pszPath);
+
+ /* Free the memory allocated by ConvertSidToStringSidW */
+ if(!hToken && hToken != (HANDLE)-1)
+ LocalFree(userPrefix);
+