次のコードを使用してC#からバッチファイルを実行しています。次のコードは、私のWindowsサービスの一部です。このコードはWindows XPでは問題なく動作しますが、Windowsサーバー2003 OSにWindowsサービスを展開すると、終了コード1(失敗)が返されます。誰かが私が行方不明を知っていますか? Windowsサービスに特別な許可を与える必要がありますか?サービスはローカルシステムサービスとしてインストールされます。Windowsサーバー2003のWindowsサービスからバッチファイルを実行できませんOS
ProcessStartInfo psi = new ProcessStartInfo();
//specify the name and arguments to pass to the command prompt
psi.FileName = ConfigurationManager.AppSettings["BatchFilePath"];
psi.Arguments = fileName;
//Create new process and set the starting information
Process p = new Process();
p.StartInfo = psi;
//Set this so that you can tell when the process has completed
p.EnableRaisingEvents = true;
p.Start();
//wait until the process has completed
while (!p.HasExited)
{
System.Threading.Thread.Sleep(1000);
}
//check to see what the exit code was
if (p.ExitCode != 0)
{
logger.Write("Exit Code" + p.ExitCode);
}
成功したバッチファイルは何ですか? – Oded
成功すると0が返されます –
Windows Server 2003では、コマンドプロンプトから直接バッチファイルを実行でき、正常に動作します。しかし、Windowsサービスからはうまくいきません。 –