473,325 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Environment for other user than running the app

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
3 3263
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: John Bowman | last post by:
Hi All, I've got a simple wrapper static test method on a class to expand the environment variables on a specified string: public static string ExpandEnvironmentStr(string Str) { return...
10
by: Edward | last post by:
I've just taken over maintaining a system from a colleague who has left. I find the following line in her code: Dim params(2) As SqlClient.SqlParameter params(0) = New...
5
by: Dominic | last post by:
My question is about how to maintain view state in mobile ASP.NET across postback / request in a web farm environment. First of all, let's assume the web-farm does NOT use stick-session feature....
15
by: Rob Nicholson | last post by:
A consequence of the ASP.NET architecture on IIS has just hit home with a big thud. It's to do with shared variables. Consider a module like this: Public Module Functions Public GlobalName As...
6
by: Fuzzyman | last post by:
Hello all, I would like to set a Windows Environment variable for another (non-child) process. This means that the following *doesn't* work : :: os.environ = value In the ``win32api``...
4
by: Peter Kirk | last post by:
Hi I would like to ask a little bit about the value Environment.Newline: what is it and what is the point of it? Ok, I can see in the docs that it represents "newline" for the current platform -...
2
by: ANarula | last post by:
I am running into a strange problem. I have perl script which reads the "APPDATA" environment variable, and does some work on that directory. When I a launch this script from Command Prompt, it...
2
by: Bjarne | last post by:
Dear all, although being a user of PHP and other scripting-languages for years, I have not taken part in any large projects based on PHP. Thus, I don't really know how real PHP-applications are...
2
by: Henry Hollenberg | last post by:
Hello, I have written a script that uses environment variables set during a particular users login in ".bash_profile" and ".profile". I have changed to that users uid and gid in my python...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.