当我执行一个进程并尝试重定向输出/错误时,出现以下错误:
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、“进程”选项卡并任意开始终止进程,运气好的话,您将击中邪恶者。在 superuser.com 询问有关使这台机器再次稳定的问题
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)