My software is still required to support Windows XP. In it I am calling SHGetKnownFolderPath API from the Windows service to obtain user-specific paths (such as FOLDERID_Desktop
) by hToken
. Since that API is not supported on XP, I'm curious if there are any alternative ways to do this on that OS?
1 Answers
The proper function to use would be SHGetFolderLocation, passing either NULL
or -1
as the access token:
hToken [in]
Type: HANDLE
An access token that can be used to represent a particular user. It is usually set to NULL, but it may be needed when there are multiple users for those folders that are treated as belonging to a single user. The most commonly used folder of this type is My Documents. The calling application is responsible for correct impersonation when hToken is non-NULL. It must have appropriate security privileges for the particular user, and the user's registry hive must be currently mounted. See Access Control for further discussion of access control issues.
Assigning the hToken parameter a value of -1 indicates the Default User. This allows clients of SHGetFolderLocation to find folder locations (such as the Desktop folder) for the Default User. The Default User user profile is duplicated when any new user account is created, and includes special folders such as My Documents and Desktop. Any items added to the Default User folder also appear in any new user account.

- 123,280
- 14
- 225
- 444
-
1Very nice find. Appreciate it! In my case though, `SHGetFolderPath` its twin API, would work better as the one returning an actual folder path. Thanks again! – ahmd0 Feb 26 '14 at 23:46
-
1`SHGetFolderLocation()` returns a `PIDL` that you can convert to a path using `SHGetPathFromIDList()`. – Remy Lebeau Feb 27 '14 at 00:17
-
@RemyLebeau: Yes, I know. But why use two APIs when I can do it with one. (In my case I need it for a desktop path only.) – ahmd0 Feb 27 '14 at 01:10
-
1@ahmd0: `SHGetFolderPath()` (and `SHGetSpecialFolderPath()`) did not exist when PIDLs were first introduced, they were added later. So it all depends on how far back you need to support older OS versions. If you have to go further back than Win2K, then you can use `GetProcAddress()` to load `SHGetFolderPath()` and if it is nt available then provide your own wrapper that uses `SHGetFolderLocation()` and `SHGetPathFromIDList()`. – Remy Lebeau Feb 27 '14 at 01:18
-
@RemyLebeau: Luckily XP is as far as I need to go. Man, I can't imagine anyone using Win2K these days. We're actually "praying" now for people to stop using XP, which is pretty ancient by today's standards anyway and gives developers a lot of headache (as you probably know.) – ahmd0 Feb 27 '14 at 01:23
-
1@ahmd0: I still use XP for all of my development VMs :) Fairly light-weight, no UAC bull**** to deal with, etc. – Remy Lebeau Feb 27 '14 at 01:28