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

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

问题描述

我使用下面的code到火IEXPLORE进程。这是一个简单的控制台应用程序完成的。

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

public static void StartIExplorer()
        {
            ProcessStartInfo 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);
            }

        }

以上code抛出错误{系统找不到指定文件}。不指定用户凭据运行时,同样的code正常工作。我不知道为什么它是引发此错误。

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.

有人能解释一下吗?

感谢。

推荐答案

尝试替换您的初始code:

Try to replace your initialization code with:

ProcessStartInfo info = new ProcessStartInfo(@"C:\Program Files\Internet Explorer\iexplore.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天全站免登陆