views:

77

answers:

1

I want to be able to retrieve Windows "special paths" (e.g. temporary files folder, desktop) for user accounts, but from a service.

I know the normal way to do this is by using SHGetFolderPath with the appropriate CSIDL for the folder type. Is there any way to get this type of info for each user without the service having to log in as each user in turn?

+1  A: 

I'm no expert on this, but it seems you can use the hToken argument to SHGetFolderPath to pass in another user's token. I think you can create such a token using impersonation.

If that does not work: these folders are in the registry under HKEY_USERS/<user's-sid>/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders. How to get the SID is explained in this question. It's in C# but I think it'll actually be easier in C++.

Thomas
I don't think impersonation would work for me as (AFAIK) the user would need to be logged on at the time, and I want to do this for all users in one sweep. I will check out the Registry approach, though, looks promising, thank you.
snowcrash09
Sadly the Registry approach doesn't work either - other user's branches under HKEY_USERS aren't mounted until those users are logged in. Thanks for the idea though.
snowcrash09
In that case, you'll have no choice but to make the service log in as every user, because even API functions can't read from a registry key they cannot access...
Thomas