Process.Start and “The system cannot find the path specified”

不想你离开。 提交于 2021-02-11 15:14:26

问题


I am trying to run a console application from a mapped drive (T:\ is a mapped drive for a shared network folder) and get the error:

The system cannot find the path specified.

Why do I get this error? The administrator credentials are correct.

var password = new SecureString();
password.AppendChar(Convert.ToChar("P"));
password.AppendChar(Convert.ToChar("a"));
password.AppendChar(Convert.ToChar("a"));
password.AppendChar(Convert.ToChar("s"));
Process.Start(@"t:\ca\test.exe"), "", "Administrator", password, "domain");

回答1:


Check if the mapped drive T: is also correctly mapped for the Administrator account.

Also, I'm not sure, but the Administrator must probably be logged in for the mapped drive to be available.

You could also try the following, starting cmd.exe, mapping your UNC path and then calling the application:

var password = new SecureString();
password.AppendChar(Convert.ToChar("P"));
password.AppendChar(Convert.ToChar("a"));
password.AppendChar(Convert.ToChar("a"));
password.AppendChar(Convert.ToChar("s"));

var startInfo = new ProcessStartInfo();

startInfo.FileName = "cmd.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.UserName = "Administrator";
startInfo.Password = password;
startInfo.Domain = "domain";

var process = Process.Start(startInfo);

process.BeginOutputReadLine();
process.StandardInput.WriteLine(@"pushd \\your_unc_path\ca");
process.StandardInput.WriteLine("test.exe");
process.StandardInput.WriteLine("exit");

process.WaitForExit();


来源:https://stackoverflow.com/questions/8310294/process-start-and-the-system-cannot-find-the-path-specified

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!