Running CMD as administrator with an argument from C#

后端 未结 5 2194
一向
一向 2020-12-10 16:54

I want to run cmd.exe as administrator with arguments from C# in order to prevent a UAC popup. This is necessary in order to use it as an automated installation

5条回答
  •  误落风尘
    2020-12-10 17:40

    There is at least one problem with your command, this line:

    Arguments = "/user:Administrator cmd /K " + command
    

    Should be:

    Arguments = "/user:Administrator \"cmd /K " + command + "\""
    

    Also, this won't work as a fully automated process, because it will ask for the Administrator's password which in Windows Vista and newer is not known.

提交回复
热议问题