我正在使用以下代码来触发 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/