在错误的Process.Start() - 该系统找不到指定的文件找不到、错误、文件、系统

2023-09-02 21:44:05 作者:朕要回幼儿园深造

我使用下面的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 FilesInternet Exploreriexplore.exe");

使用上的Process.Start非完整文件路径只有当文件在System32文件夹中找到工作。

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