问题
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