David,
This would be the easy way to do it, but not practical at all.
Are you doing this in an operation that is not triggered by something
else? For example, is a call over a socket, or a named pipe being made to
you (or remoting). Something where you can flow the identity of the caller
to the service? If so, you should use impersonation to do that, otherwise,
you need to fabricate the token yourself.
You might be able to make a call to NtCreateToken (an undocumented
function, documentation at
http://undocumented.ntinternals.net/...eateToken.html )
, but I'm not sure that it would work. If so, your calls would have to look
something like this:
UserSid = LookupAccountName(UserName);
EnablePrivilege(SeCreateTokenP*rivilege);
hToken = NtCreateToken(UserSid,UserGrou*p,UserPrivilege);
DisablePrivilege(SeCreateToken*Privilege);
From there, you can pass the token to the SHGetFolderPath API.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"David Meier" <Da********@discussions.microsoft.com> wrote in message
news:DA**********************************@microsof t.com...
Hi Nicholas,
first, thanks for the reply. Does your solution mean, the service needs to
know the password for the user in order to get the impersonation handle?
Is
there no other way?
Dave
"Nicholas Paldino [.NET/C# MVP]" wrote:
David,
You will have to call the SHGetFolderPath API through the P/Invoke
layer
to get this. When you call it, you will have to create an impersonation
token for the user to pass in the hToken parameter, so you can get that
specific user's path information. This would mean a call to LogonUser to
get the impersonation handle representing that user.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"David Meier" <Da********@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com... > Hi,
>
> is it possible to get the environment variables for users other than
> the
> user that is currently executing the application?
>
> For example if I run a system service, how can the service find the
> SpecialFolder.InternetCache of a certain user?
>
> Thanks for input. Dave.