Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Operating System - Microsoft
cancel
Showing results for 
Search instead for 
Did you mean: 

Set up a .BAT file as a Windows Service?

SOLVED
Go to solution
Sheldon Smith
Honored Contributor

Set up a .BAT file as a Windows Service?

I have a command procedure (.BAT file) which sets several environment variables and then starts a command line executable. The environment variables are to add the date and time to an output file for the executable. The program then runs until it either reaches its stop timer or is aborted due to some outside intervention.

I would like to have some method of running a .BAT file so as to not require an interactive session. I am wondering if it is possible to set up a .BAT file as a Windows Service? Then I could have it automatically start once the system is up, not to mention automatically REstart if and when the executable stops for any reason.
I would also prefer a solution that does not require any third-party (commercial) software.

Other ideas are welcome.

Note: While I work for Hewlett Packard Enterprise, all of my comments (whether noted or not), are my own and are not any official representation of the company.
----------
If my post was useful, click on my KUDOS! thumb below!
5 REPLIES
Phil.Howell
Honored Contributor

Re: Set up a .BAT file as a Windows Service?

You could define your command procedure as a scheduled task that only runs at system startup. Ensure that "Run only if logged on" is not checked.
You can get software to convert batch files to services - google for bat2exe
Phil
Sheldon Smith
Honored Contributor

Re: Set up a .BAT file as a Windows Service?

Still looking for an idea to get it to automatically restart if and when it stops.

Note: While I work for Hewlett Packard Enterprise, all of my comments (whether noted or not), are my own and are not any official representation of the company.
----------
If my post was useful, click on my KUDOS! thumb below!
BPatrick
Trusted Contributor
Solution

Re: Set up a .BAT file as a Windows Service?

Sheldon,

You can setup the batch file as a windows service. There is a tool available in windows resource kit with a graphical interface which will make it easier for you to configure the service - srvinstw.exe. This is a microsoft tool and you could either download it or find it in windows cd.

Cheers
Patrick
BPatrick
Trusted Contributor

Re: Set up a .BAT file as a Windows Service?

Sheldon,

srvinstw program is attached as zip herewith in case you dont have the resource kit with you.


Patrick
Sheldon Smith
Honored Contributor

Re: Set up a .BAT file as a Windows Service?

Once the service template was created, it was just a matter of pointing it at the .CMD file.

Note: While I work for Hewlett Packard Enterprise, all of my comments (whether noted or not), are my own and are not any official representation of the company.
----------
If my post was useful, click on my KUDOS! thumb below!