当我执行一个流程并尝试重定向输出/错误时,我收到以下错误:
System.ComponentModel.Win32Exception (0x80004005): Access is denied
at System.Diagnostics.Process.CreatePipe(SafeFileHandle& parentHandle, SafeFileHandle& childHandle, Boolean parentInputs)
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
...
有什么问题吗?这是一个复制品:
string path = "C:\\batch.cmd";
using (Process proc = new Process())
{
bool pathExists = File.Exists(path);
if(!pathExists) throw new ArgumentException("Path doesnt exist");
proc.StartInfo.FileName = path;
proc.StartInfo.WorkingDirectory = workingDir.FullName;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start(); //Exception thrown here
proc.WaitForExit();
}
最佳答案
没有正当理由导致此失败,代码尚未达到可以执行任何安全敏感操作的程度。这是环境问题,您机器上的某些东西正在干扰。首先重新启动,然后禁用反恶意软件。如果这没有帮助,那么使用 TaskMgr.exe,Processes 选项卡并任意开始终止进程,运气好的话你会击中作恶者。在 superuser.com 上询问有关使这台机器再次稳定的问题
关于c# - Process.Start() 抛出 "Access Denied"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8548439/