Process.Start() 出错 -- 系统找不到指定的文件 [英] Error in Process.Start() -- The system cannot find the file specified

查看:61
本文介绍了Process.Start() 出错 -- 系统找不到指定的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using the following code to fire the iexplore process. This is done in a simple console app.

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);
    }
}

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

The above code is throwing the error The system cannot find the file specified. The same code when run without specifying the user credentials works fine. I am not sure why it is throwing this error.

谁能解释一下?

推荐答案

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

Try to replace your initialization code with:

ProcessStartInfo info 
    = new ProcessStartInfo(@"C:Program FilesInternet Exploreriexplore.exe");

Process.Start 上使用非完整文件路径仅适用于在 System32 文件夹中找到的文件.

Using non full filepath on Process.Start only works if the file is found in System32 folder.

这篇关于Process.Start() 出错 -- 系统找不到指定的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆