c# - Process.Start() 中的错误——系统找不到指定的文件

标签 c# .net process

我正在使用以下代码来触发 iexplore 进程。这是在一个简单的控制台应用程序中完成的。

public static void StartIExplorer()
{
    var info = new ProcessStartInfo("iexplore");
    info.UseShellExecute = false;
    info.RedirectStandardInput = true;
    info.RedirectStandardOutput = true;
    info.RedirectStandardError = true;

    string password = "password";
    SecureString securePassword = new SecureString();

    for (int i = 0; i < password.Length; i++)
        securePassword.AppendChar(Convert.ToChar(password[i]));

    info.UserName = "userName";
    info.Password = securePassword;
    info.Domain = "domain";

    try
    {
        Process.Start(info);
    }
    catch (System.ComponentModel.Win32Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

上面的代码抛出错误系统找不到指定的文件。在不指定用户凭据的情况下运行相同的代码可以正常工作。我不确定为什么会抛出此错误。

有人可以解释一下吗?

最佳答案

尝试将您的初始化代码替换为:

ProcessStartInfo info 
    = new ProcessStartInfo(@"C:\Program Files\Internet Explorer\iexplore.exe");

只有在 System32 文件夹中找到文件时,在 Process.Start 上使用非完整文件路径才有效。

关于c# - Process.Start() 中的错误——系统找不到指定的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2369119/

相关文章:

c# - 使用 Mysql 表填充 C# ListView

c# - MVVM、WPF 和验证

c# - 部分读取从 c# 应用程序创建的另一个进程的标准输出

c# - Windows7 中的 VS 2010 设计器错误 'Could not find type XYZ'。在 XP 中工作正常

c# - 验证应用程序是否正在运行,如果没有则启动它

c# - Process.Exited 并不总是触发

c# - Azure 事件网格订阅控制台应用程序

c# - 将数据集转换为文本文件制表符分隔文件

c# - 仅在 Vista/Windows Server 2008 上出现 P/Invoke 错误

c# - 如何在 WinForms 应用程序的 Windows 安装程序期间获取用户输入?