Running A Batch file in a windows service
-
Hi All I am trying to run a batch file in a windows service. It seems to sort of work as I can see a cmd.exe process running when the service executes it but the batch file does not seem to run the contents of the batch. I am using process.start("c:\mybatch.bat") I run the service under my admin account. When I run a similar program in vb.net forms app it works fine. can anyone help or have any suggestions to rectifiy this ? Cheers Dom
-
Hi All I am trying to run a batch file in a windows service. It seems to sort of work as I can see a cmd.exe process running when the service executes it but the batch file does not seem to run the contents of the batch. I am using process.start("c:\mybatch.bat") I run the service under my admin account. When I run a similar program in vb.net forms app it works fine. can anyone help or have any suggestions to rectifiy this ? Cheers Dom
-
Try using: System.Diagnostics.process.start("C:\mybatch.bat")
Caffeination, fuels the programming nation!
-
Hi All I am trying to run a batch file in a windows service. It seems to sort of work as I can see a cmd.exe process running when the service executes it but the batch file does not seem to run the contents of the batch. I am using process.start("c:\mybatch.bat") I run the service under my admin account. When I run a similar program in vb.net forms app it works fine. can anyone help or have any suggestions to rectifiy this ? Cheers Dom
-
Hi All I am trying to run a batch file in a windows service. It seems to sort of work as I can see a cmd.exe process running when the service executes it but the batch file does not seem to run the contents of the batch. I am using process.start("c:\mybatch.bat") I run the service under my admin account. When I run a similar program in vb.net forms app it works fine. can anyone help or have any suggestions to rectifiy this ? Cheers Dom
If your batch file starts an interactive process, it's looking for user input, you'll never see it in the default configuration for a Windows Service. All Windows Services, by default, run under a seperate (non-visible) desktop. In order for a service to be able to interact with the visible desktop, you have to go into the Services manager (Start/Run SERVICES.MSC), find your service, get properties on it, then go to the LogOn tab and enable the "Local System account" login, then enable "Allow service to interact with the desktop".
Dave Kreskowiak Microsoft MVP - Visual Basic