Start Process with administrator right in C#

后端 未结 5 1008
醉酒成梦
醉酒成梦 2020-12-06 07:04

I have to start a command line program with System.Diagnostics.Process.Start() and run it as Administrator.

This action will also be run by a Scheduled Task every da

5条回答
  •  抹茶落季
    2020-12-06 07:32

    If you are using scheduled tasks, you can set the user and password for the task to run under.

    Use the administrator credentials on the task and you will be fine.

    With Process.Start, you need to supply the UserName and Password for the ProcessStartInfo:

    Process p = new Process("pathto.exe");
    p.StartInfo.UserName = "Administrator";
    p.StartInfo.Password = "password";
    p.Start();
    

提交回复
热议问题