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.

Sameet
  • 2,191
  • 7
  • 28
  • 55

2 Answers2

0

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

Community
  • 1
  • 1
Iain Ward
  • 9,850
  • 5
  • 34
  • 41
  • 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. – Sameet Jul 02 '10 at 14:52
  • 1
    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? – Iain Ward Jul 02 '10 at 15:15
0

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
  • 489,969
  • 99
  • 883
  • 1,009