我有一个非常简单的批处理文件:
echo Text > Test.txt
此文件保存在这里:
R:\Testing123.bat
完整的 UNC 途径是
\\imfile\depart$\DB\Testing123.bat
在我的控制台应用程序中,以下运行:
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.WorkingDirectory = @"R:\";
myProcess.StartInfo.FileName = @"Testing123.bat";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
如果我使用完整的路径,这不会运行:
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = true ;
myProcess.StartInfo.WorkingDirectory = @"\\imfile\depart$\DB\";
myProcess.StartInfo.FileName = @"Testing123.bat";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
我不能将这些 UNC 路径用于 WorkingDirectory 属性吗?我认为在编程时使用这些路径总是最佳实践?
编辑
使用其中一个建议,我现在有以下不幸仍然不起作用:
{
Process myP = new Process();
myP.StartInfo.UseShellExecute = false;
string myString = @"pushd \\imfile\depart$\DB";
myP.StartInfo.FileName = "cmd";
myP.StartInfo.Arguments = myString;
myP.StartInfo.CreateNoWindow = true;
myP.Start();
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = true ;
myProcess.StartInfo.WorkingDirectory = @"\\imfile\depart$\DB";
//myProcess.StartInfo.WorkingDirectory = @"R:\";
myProcess.StartInfo.FileName = @"Testing123.bat";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
}