How to run an interactive batch file on windows from a service?

Cannot run a batch file from a Windows service in Windows server 2003 OS

  • 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 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); }

  • Answer:

    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

Khawar Yunus at Stack Overflow Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.