Process.Start()抛出"Access Denied"(拒绝访问)消息.错误 [英] Process.Start() throws an "Access Denied" error
问题描述
当我执行一个过程并尝试重定向输出/错误时,出现以下错误:
When I execute a process through and try to redirect the output/error, I get the following error:
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)
...
可能是什么问题?这是一个复制品:
What could be wrong? Here is a repro:
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上询问有关使计算机稳定的问题
No decent reason for this to fail, the code has not yet gotten to a point where it would do anything security-sensitive. This is environmental, something on your machine is interfering. Reboot first, disable anti-malware next. If that doesn't help then use TaskMgr.exe, Processes tab and arbitrarily start killing processes, with some luck you'll hit the evil-doer. Ask questions about getting this machine stable again at superuser.com
这篇关于Process.Start()抛出"Access Denied"(拒绝访问)消息.错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!