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
Related Q & A:
- Is there a limit on the size of a new file or a text file?Best solution by Stack Overflow
- How can I burn a .rmvb file onto a DVD for viewing on a regular DVD player?Best solution by Yahoo! Answers
- Is there any way of getting VHS tapes into a video file on a computer?Best solution by cnet.com
- Where can I find a good guide for a civil service exam?
- How to make a batch file copy itself?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.