By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,010 Members | 1,266 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,010 IT Pros & Developers. It's quick & easy.

Environment for other user than running the app

P: n/a
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.
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

Nov 17 '05 #2

P: n/a
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.


Nov 17 '05 #3

P: n/a
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.


Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.