c# - Process.Start() 抛出 "Access Denied"错误

标签 c# redirect process

当我执行一个流程并尝试重定向输出/错误时,我收到以下错误:

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/

相关文章:

c# - WPF 组合框通配符子字符串搜索

c# - 并行排序算法

c# - 在 Linq 中动态添加谓词

C#;重定向处理标准错误但不处理其标准输出

process - 当 JVM 被杀死时,Safari 崩溃了

c# - 带有 "dynamic"参数名称的 IN 语句的 Dapper AddDynamicParams

Python 请求 - 重定向后的身份验证

apache 反向代理更改 url

scala - 如何在 Scala 中运行外部进程并获取退出代码和输出?

java - 如何从 Java 运行 bash 脚本