I am using the following code to run a batch file from C#. The following code is part of my windows service. This code works perfectly fine in Windows XP but when I deploy my windows service to Windows server 2003 OS it returns exit code 1 (failure). Does someone know what I am missing? Do I need to give some special permission to the windows service? The service is installed as a Local System service.
ProcessStartInfo psi = new ProcessStartInfo();
//specify the name and arguments to pass t开发者_StackOverflow中文版o 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);
}
My next set would be to try setting the service to run as the user you're logged in as when it works. That way you'll know whether it is something specific to the Network Service account that's stopping it working
精彩评论