views:

40

answers:

2

I'm running a windows service (written using .NET) as the user - LocalSystem.

From the service, I need to start a process but as the currently logged on user. If I user Process.Start(process_name), it runs with the privilege of the service by default - that's as LocalSystem. How do I impersonate the currently logged on user and run the process under the same?

EDIT: I won't have access to user credentials - I wouldn't know the password of the logged in user

EDIT2: The 2nd comment in the post marked as answer is what helped.

A: 

A question similar to this has already been asked Setting Service to Run as Current User

w69rdy
Yeah, that's a little different. I install and run my service as - LocalSystem. I need this service, which is running with elevated privileges to start a process with lower privilege - that's as the current user.
SaM
Ah I see, ok what about getting the service to create a scheduled task that will run your program? Or put an entry into the startup menu to run when then login?
w69rdy
+1  A: 

You can start a process using ProcessStartInfo - it allows you to set a username and password for the new process to start as:

ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.UserName = myUserName;
startInfo.Password = myUserPassword;
startInfo.Arguments = "www.northwindtraders.com";
Process.Start(startInfo);

Update: (following update to question)

You may be able to use RunAs for this - if someone else provides the credentials.

Oded
oh sorry, forgot to mention - i cannot rely on passing user credentials - no password :)
SaM