Process.Start()中的错误—系统找不到指定的文件
我正在使用以下代码来触发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);
}
}
上面的代码抛出错误The system cannot find the file
specified。在不指定用户凭据的情况下运行相同的代码即可正常工作。我不确定为什么会引发此错误。
有人可以解释一下吗?
回答:
尝试将初始化代码替换为:
ProcessStartInfo info = new ProcessStartInfo(@"C:\Program Files\Internet Explorer\iexplore.exe");
Process.Start
仅当在System32文件夹中找到文件时,才使用非完整文件路径。
以上是 Process.Start()中的错误—系统找不到指定的文件 的全部内容, 来源链接: utcz.com/qa/434733.html