Operating System - Microsoft
1752758 Members
4757 Online
108789 Solutions
New Discussion юеВ

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

 
SOLVED
Go to solution
Sheldon Smith
HPE Pro

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 am an HPE Employee, all of my comments (whether noted or not), are my own and are not any official representation of the company

Accept or Kudo

5 REPLIES 5
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
HPE Pro

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 am an HPE Employee, all of my comments (whether noted or not), are my own and are not any official representation of the company

Accept or Kudo

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
HPE Pro

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 am an HPE Employee, all of my comments (whether noted or not), are my own and are not any official representation of the company

Accept or Kudo