# Restart a Service on a Remote Computer



## jheer

I am looking for the easiest way to automatically stop and restart a service on another server if the one server is ever rebooted. I'm running Win2003 Server. 
Is there an easy way to set this up or do I need to create a script that will run on the main server and will trigger the restart of the service on the other computer on startup? Anyone have any suggestions? :1angel:


----------



## djaburg

If it's a service, then why not go in to services and set it to automatic? The other option is to create a .bat file using:

net start_servicename_

ex: net start mssqlserver

and have that run during startup. I would, however, first look in the services applet and make that the service you need started is in there and set to auto.

The .bat file is more handy for things like stopping a service, running a program, and then restarting the service when the program is done. I've set up things like rsync to sync shared directories between servers where some of the files are being used by the sql server installed with programs like act and I stop the service, sync the files, and then restart the service.


----------



## Cellus

Your best bet would be to access the Services MMC snap-in (run _services.msc_) and make sure the Startup Type is set to *Automatic*. This will cause the service to automatically be started whenever the server starts up.

Scripting it using the net command is only really useful when the server is already running, such as the example given by djaburg. If you're just wanting the service to start up when the server starts up, then use the Services MMC snap-in.


----------



## jheer

djaburg said:


> If it's a service, then why not go in to services and set it to automatic? The other option is to create a .bat file using:
> 
> net start_servicename_
> 
> ex: net start mssqlserver
> 
> and have that run during startup. I would, however, first look in the services applet and make that the service you need started is in there and set to auto.
> 
> The .bat file is more handy for things like stopping a service, running a program, and then restarting the service when the program is done. I've set up things like rsync to sync shared directories between servers where some of the files are being used by the sql server installed with programs like act and I stop the service, sync the files, and then restart the service.


Thanks Djaburg,

The service is set to automatic. What I am looking to do is that whenever my SQL Server is rebooted, upon startup I want SQL to restart Apache Tomcat on *3 different servers*. These servers are dependent on the SQL connection for the App. to run. Normally if my SQL server ever goes down or is rebooted I have to stop/start Apache Tomcat manually on each of the 3servers. I want SQL to do this for me automatically once it starts up. 

Do you have any sample .bat files similar to what I'm looking for?


----------



## djaburg

Try this:

SC [\\server] [command] [service_name] [Options]

so perhaps it could be used like this:

sc \\server start mssqlserver

I'm assuming you're running this from a computer where you have administator access (like a domain controller) and also have administrator access to the remote computers. I would think if there's authentication issues, it might not work correctly.


----------



## minimeister

Can anyone provide an answer to the question instead of just providing alternatives?


----------



## bilbus

i would use the SC command on a login script, and like DJ said .. have it start the service if stopped on the remote pc.


----------



## Vishnu Chander

wil the sc command be able to change the startup type ?? of the remote server...


----------



## bilbus

I think so.


----------



## Vishnu Chander

To connect to the remote computer the server service on the remote computer must be running .. am i right.. ?


----------



## bilbus

the server service (ntlanman) needs to be running, not the server you are starting.

So say you are trying to start the firewall service, only the windows "server sevice" needs to be running. So you can start and stop the firewall service with no issues.


----------



## wycito

supposing you have access to another computer in the same subnet and admin rights you can go to services.msc in the computer in the same subnet and in the left (Services(local)) right click and choose connecto to another computer, choose the name of the computer you want to administer or ip address for that matter and go to connect, that should take you to the services page in the desired computer, server.

Regards


----------

