的Process.Start和“系统找不到指定的路径”

的Process.Start和“系统找不到指定的路径”

问题描述:

我试图运行映射驱动器控制台应用程序(T:\是共享网络文件夹映射驱动器),并且得到错误:的Process.Start和“系统找不到指定的路径”

The system cannot find the path specified.

为什么我得到这个错误?管理员凭据是正确的。

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"); 

检查映射驱动器T:也正确映射为Administrator帐户。

此外,我不确定,但管理员必须登录才能使映射驱动器可用。

您也可以尝试以下,开始cmd.exe,映射你的UNC路径,然后调用应用程序:

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(); 
+0

如何做到这一点?我已经从我运行应用程序的相同帐户映射网络驱动器。 – Tomas

+0

如果您已经使用管理员帐户登录,您为什么要用该帐户调用'Process.Start'? –

+0

我得到“发布者无法验证”安全对话框,我认为如果我使用管理员凭据运行应用程序,对话框将不会显示。 – Tomas