私は非常に単純なバッチファイルを持っています:
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プロパティに使用できませんか?プログラミングするときは、これらの経路を使用することが常にベストプラクティスだと思いましたか?
編集
提案の1つを使用すると、残念ながらまだ機能しない次のものがあります。
{
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();
}