locked
Run a batch job as Windows service RRS feed

  • Question

  • Hello There,

    I have created a small batch job. And we need this batch job to always run.

    We do not want to login to the machine to start the job again and again.

    I tried using sc create and srvany to create a service . And followed few steps which i got online .

    The service I create starts fine , but it doesn't run the batch file. Task manager shows nothing.

    The steps I followed :

    1.Copy srvany.exe it to Win2008R2 server (e.g. C:\Windows\System32\ ).
    2.Use "sc " to create a new service that launches "srvany " (e.g. sc create MyService binPath= C:\Windows\System32\srvany.exe DisplayName= "My Custom Service" )
    3.Using RegEdit : create a "Parameters " key for your service (e.g. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService\Paramaters\ )
    4.Using RegEdit : within the newly created "Parameters " key , create a string value called "Application " and enter the full path to the application you are wanting to run as a service.  (No quotes required.)

    Could anyone help me here please.  

    Thursday, November 22, 2012 7:53 PM

Answers

  • Your steps look fine. Are you sure that the batch job is not starting but exiting quickly? Use Task Manager (or better yet, Microsoft's free Process Explorer) to get a clearer picture of what is happening.

    What does your batch job do? Realize that it will be running in the LocalSystem account (the default for Windows Services) and some commands that work fine as a regular user may yield unexpected results when run as LocalSystem. You can change the user via the Log On tab.

    And since Srvany doesn't provide any logging, situations like yours can be very difficult to diagnose. I suggest using the free 30-day trial of AlwaysUp (a commercial utility designed to run anything as a service) to help you figure out what is going wrong. You can switch back to Srvany once things are working. Follow this tutorial to setup your batch file as a service.


    • Edited by Core Tech Saturday, November 24, 2012 4:15 PM
    • Marked as answer by Boo_MonstersInc Friday, November 30, 2012 4:46 AM
    Saturday, November 24, 2012 4:14 PM

All replies

  • The string value is D:\Folder_name\test.bat

    And the string name used is Application.

    Thursday, November 22, 2012 8:04 PM
  • Your steps look fine. Are you sure that the batch job is not starting but exiting quickly? Use Task Manager (or better yet, Microsoft's free Process Explorer) to get a clearer picture of what is happening.

    What does your batch job do? Realize that it will be running in the LocalSystem account (the default for Windows Services) and some commands that work fine as a regular user may yield unexpected results when run as LocalSystem. You can change the user via the Log On tab.

    And since Srvany doesn't provide any logging, situations like yours can be very difficult to diagnose. I suggest using the free 30-day trial of AlwaysUp (a commercial utility designed to run anything as a service) to help you figure out what is going wrong. You can switch back to Srvany once things are working. Follow this tutorial to setup your batch file as a service.


    • Edited by Core Tech Saturday, November 24, 2012 4:15 PM
    • Marked as answer by Boo_MonstersInc Friday, November 30, 2012 4:46 AM
    Saturday, November 24, 2012 4:14 PM