Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping Services From The Command Line

Status
Not open for further replies.

nhidalgo

MIS
Jun 13, 2001
619
US
Is there a command that is used to stop or start a service from the command line? I'm want to right a script that stops a service updates some dependant files and then restarts the service. Any help would be great.

Nick
 
net stop "servicename"
net start "servicename"

to find the existing servicenames, type: "net start", and it will show you a list. Most of the services have two names that can be used to start or stop them. The long name, like "Microsoft Exchange Internet Mail Service", and a short name, like "msexcimc". "net start dns" or "net start dns server" will both work.
 
Thanks for the help. I think this will do the trick.

Nick
 
If you need to know if the service is already running or is stopped and needs to be started then use Windows Script Host to detect and start or stop...can post if required.
 
TheOtherKiwi - can this enable a disabled service as well? -----------------------------------------------------
"It's true, its damn true!"
-----------------------------------------------------
 
How would i do that, i'm not familiar with windows script host.

Nick
 
e.g BAT

"net stop XXXX" in a batch file or use ADSI or WMI...

e.g. ADSI

Set MessengerServiceObj = GetObject("WinNT://ComputerName/messenger")

MessengerServiceObj.stop

Set MessengerServiceObj = Nothing

e.g. WMI

Restart service on remote machine...

For Each Service in GetObject("winmgmts:{impersonationLevel=impersonate}!//test01.company.com").ExecQuery
("Associators of { Win32_service.Name = ""NetDDE"" } Where AssocClass = Win32_DependentService Role = Dependent" )

If Service.State = Stopped Then
Service.Start ()
End If
Next

Check for loads of examples...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top