07.05.07

Restarting services from a batch

Posted in windows at 2:33 pm by Hedwig Lodrigo

When some of your servers are running services which leak memory, you’ll find yourself in the position where you are restarting these services all the time. A good admin will get tired off this very soon and look for a way to automate this.
Automating this is very easy. You can use the windows scheduled tasks to run a bat file.

The bat file has to contain something similar to this:

net stop "ASP.NET State Service"
net stop "FTP Publishing Service"
net stop "ReportServer"
net stop "World Wide Web Publishing Service"
net stop "Simple Mail Transport Protocol (SMTP)"
net stop "IIS Admin Service"

net start "IIS Admin Service"
net start "Simple Mail Transport Protocol (SMTP)"
net start "World Wide Web Publishing Service"
net start "ReportServer"
net start "FTP Publishing Service"
net start "ASP.NET State Service"

When restarting theses services you must lookout for dependencies tho. For instance in the above bat file the World Wide Web Publishing Service depends on the IIS Admin Service. this means you can’t restart the IIS admin Service when the World Wide Web Publishing Service is still running.

Comments are closed.