我需要从cd.bat运行此命令
powershell -windowstyle hidden -command "Start-Process cmd -ArgumentList '/c takeown /f \"C:\Windows\System32\wuaueng.dll\" && icacls \"C:\Windows\System32\wuaueng.dll\" /grant *S-1-3-4:F /t /c /l' -Verb runAs"
当我右键单击该BAT手动运行->以管理员身份运行时,当我尝试从CMD运行时,它运行完美:
Process.Start(Application.StartupPath + "\\cd.bat");
CMD启动但命令不起作用,为什么?
我的应用程序具有清单中的管理权限
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
我也尝试使用普通命令:
proc.StartInfo.FileName = "CMD.exe";
proc.StartInfo.Arguments = "/c powershell -windowstyle hidden -command \"Start - Process cmd - ArgumentList '/c takeown /f \"C:\\Windows\\System32\\wuaueng.dll\" && icacls \"C:\\Windows\\System32\\wuaueng.dll\" /grant *S-1-3-4:F /t /c /l' - Verb runAs\"";
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
和
var p = new Process();
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.WorkingDirectory = @"C:\Windows\System32";
p.StartInfo.Arguments = "/k powershell -windowstyle hidden -command \"Start - Process cmd - ArgumentList '/c takeown /f \"C:\\Windows\\System32\\wuaueng.dll\" && icacls \"C:\\Windows\\System32\\wuaueng.dll\" /grant *S-1-3-4:F /t /c /l' - Verb runAs\"";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = false;
p.StartInfo.UseShellExecute = false;
p.OutputDataReceived += (a, b) => line = line + b.Data + Environment.NewLine;
p.ErrorDataReceived += (a, b) => line = line + b.Data + Environment.NewLine;
p.Start();
p.BeginErrorReadLine();
p.BeginOutputReadLine();
MessageBox.Show(line);
MessageBox结果为空,因此没有错误...
相同结果=(
答案 0 :(得分:0)
解决了:
Process.Start("powershell.exe",
"-windowstyle hidden -command "
+ "Start-Process cmd -ArgumentList '/c takeown /f \"C:\\Windows\\System32\\wuaueng.dll\" && icacls \"C:\\Windows\\System32\\wuaueng.dll\" /grant *S-1-3-4:F /t /c /l' -Verb runAs"
);