Discussion:
GetFolderPath fails when impersonating
(too old to reply)
Matt Houser
2009-11-11 21:25:52 UTC
Permalink
I have a named pipe set up between 2 processes on my local computer. I am
using NamedPipeClientStream and NamedPipeServerStream. After getting the
connection, my server impersonates the client user using
NamedPipeServerStream.RunAsClient(). It then calls
Environment.GetFolderPath to get the impersonated user's Application Data
folder.

All seems to be working most of the time. However...

I have 2 domain user accounts, both of which have been logged into my
computer at one time or another. Let's call them Matt and Mary.

I am currently logged in as 'Matt'.
If I run the server as 'Mary' using "Run as different user", and I run the
client as 'Matt, then I get an exception in the call to GetFolderPath:
DllNotFoundException
Unable to load DLL 'shfolder.dll': Exception from HRESULT:
0x80070542

I am using Windows 7.

If I reverse who is running what, then it works ok. So if I impersonate
Mary in the process running as Matt, then it works.

Is "Run as different user" somehow flawed, or does this accurately depict
that there's an issue with what I am doing?

Thanks,
...Matt
Phil Wilson
2009-11-15 20:22:03 UTC
Permalink
I think some of this is might be because the user's application data folder
info is in that user's registry hive, and impersonation does not load it.
The docs for the LoadUserProfile API explain this. However the missing
shfolder Dll message is bogus because 0x80070542 errors seem to be related
to impersonation (maybe Mary doesn't have the right to impersonate).
--
Phil Wilson
Post by Matt Houser
I have a named pipe set up between 2 processes on my local computer. I am
using NamedPipeClientStream and NamedPipeServerStream. After getting the
connection, my server impersonates the client user using
NamedPipeServerStream.RunAsClient(). It then calls
Environment.GetFolderPath to get the impersonated user's Application Data
folder.
All seems to be working most of the time. However...
I have 2 domain user accounts, both of which have been logged into my
computer at one time or another. Let's call them Matt and Mary.
I am currently logged in as 'Matt'.
If I run the server as 'Mary' using "Run as different user", and I run the
DllNotFoundException
0x80070542
I am using Windows 7.
If I reverse who is running what, then it works ok. So if I impersonate
Mary in the process running as Matt, then it works.
Is "Run as different user" somehow flawed, or does this accurately depict
that there's an issue with what I am doing?
Thanks,
...Matt
Loading...