开发者

Windows Service running as LocalSystem but needs to start a process as the currently logged on user

开发者 https://www.devze.com 2023-01-06 07:16 出处:网络
I\'m running a windows service (written using .NET) a开发者_开发技巧s the user - LocalSystem. From the service, I need to start a process but as the currently logged on user. If I user Process.Start(

I'm running a windows service (written using .NET) a开发者_开发技巧s 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 question similar to this has already been asked Setting Service to Run as Current User


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消