views:

959

answers:

1

Hello all,

Is there any Win32/MFC API to get the CSIDL_LOCAL_APPDATA for any user that I want (not only the currently logged on one)? Let's say I have a list of users in the form "domain\user" and I want to get a list of their paths - is that possible?

Thanks in advance!

+3  A: 

You can get the SID for the user and then look it up under HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList and get the ProfileImagePath value.

Once you have this path, you can get CLSID_LOCAL_APPDATA for your user, convert the absolute path to a relative path to your profile and then append that relative path to the other user profile path.

However, keep in mind that this is relying on an undocumented registry key and can break in future versions of the OS. (Or, as Raymond Chan would say: "Now that you know how to do it, let me tell you why you shouldn't do it this way..." :-))

If you have a token representing the user, you can use the SHGetFolderPath or SHGetKnownFolderPath (on Vista and up). However, there are certain security restrictions and you should read up on MSDN for details.

SHGetFolderPath - http://msdn.microsoft.com/en-us/library/bb762181(VS.85).aspx SHGetKnownFolderPath - http://msdn.microsoft.com/en-us/library/bb762188(VS.85).aspx

Franci Penov
Thank you - I'll try that.
dennisV
If there is another way, I'd gladly use it :)
dennisV
SHGetFolderPath() should do the trick - this app will be run as admin, so should be fine. Thanks.
dennisV
If I can't get a token for the SHGetFolderPath(), is there any other way I could accomplish this? Thanks.
dennisV
Nope, for security reasons you should not have access to other user's folders (including their paths) unless you have impersonation priviledge and valid user token (i.e. you've been granted rights by the user somehow to do stuff on their behalf)
Franci Penov
I guess this works until either the current user gets its LOCAL_APPDATA folder moved or the user you're interested in gets its LOCAL_APPDATA folder moved. One interesting testcase would be a PC upgraded from XP to Vista, with pre- and post-upgrade users.
MSalters
Yes, it will fail if a user moves her local appdata. It will work 99% of the times and will fail miserably for your boss'es boss :-)). That's why I mentioned that's not the right way to do it. SHGetFolderPath w/ impersonation is the right way, but you need a valid user token.
Franci Penov