无法以管理员身份运行命令

时间:2018-08-15 14:26:34

标签: c#

我当前正在尝试在C#程序中运行某些命令,但是在尝试cd时出现“拒绝访问”错误。我读到将UseShellExecute更改为true可以给我管理员访问权限,但是每当执行此操作时,都会出现以下错误:

Exception thrown: 'System.PlatformNotSupportedException' in System.Diagnostics.Process.dll

我尝试将cmd.UserName设置为null,将cmd.Verb设置为“ runas”,但仍然遇到相同的错误。我还以管理员身份运行Visual Studio。问题不在于如何获得管理员访问权限,而是为什么当我尝试以管理员身份运行它时会得到异常

ProcessStartInfo cmd = new ProcessStartInfo("cmd.exe");
cmd.RedirectStandardInput = true;
cmd.UseShellExecute = false;
cmd.CreateNoWindow = false;
cmd.WindowStyle = ProcessWindowStyle.Normal;
Process console = Process.Start(cmd);
console.StandardInput.WriteLine(" cd ..");

0 个答案:

没有答案
相关问题