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.
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.
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!"
-----------------------------------------------------
"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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.