Search The Web

Sunday, March 4, 2012

start and stop services via batch file / command prompt

start and stop services via batch file / command prompt


To start and stop services with a batch file is very easy and is useful for scheduled tasks where you may want to regularly restart a service for various reasons
Firstly, you need to know the name of the service. to locate this you go to computer management -> services and look for the name of the service you need to restart. In this case we will use the Print Spooler service.
your commands to stop the service are net stop "service name" and your command to start it are net start "service name"
so to restart as a batch file would look like"
@Echo Off
REM this will restart the prince spooler service

net stop "Print Spooler"
net start "print spooler"
exit
as usual you would want to add a remark (REM) to the start of the batch file to describe what you would like to do.
you can combine these commands for restarting complex systems such as IIS. as an exambple, this series of command will restart IIS's web, FTP and SMTP services
@Echo off
REM this restarts IIS's web, SMTP and FTP services
net stop "World Wide Web Publishing Service"
net start "World Wide Web Publishing Service"
net stop "FTP Publishing Service"
net start "FTP Publishing Service"
net stop "Simple Mail Transport Protocol (SMTP)"
net start "Simple Mail Transport Protocol (SMTP)"
so as you can see this is all pretty straight forward stuff. from here you can save the batch file and add it as a scheduled task in windows (more on that later)

No comments:

Post a Comment