2
votes

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.

2

2 Answers

0
votes

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

0
votes

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.