다음 코드를 사용하여 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 서버 2003에서는 명령 프롬프트에서 직접 배치 파일을 실행할 수 있으며 정상적으로 작동합니다. 하지만 그것은 Windows 서비스에서 작동하지 않습니다. –