There is a task in BES Support site to stop the running services on endpoints, named “Stop Service”. My question is that, is it possible to stop multiple services on client with one action?
Our normal process is stopping the services one by one by taking action on aforementioned task, which is time taking.
Can anyone help me to achieve what i’m looking for?
There is not a pre-made task to do this. You could take the existing task and modify it to stop multiple services or you can create a bunch of single action tasks and put them in a baseline if that is easier.
This is very rough, but should bet you in the right direction.
action parameter query "_Services" with description "Services to stop (service1,service2,service3)" and with default value "SQLSERVERAGENT,MSSQLSERVER"
parameter "_Script" = "c:\Windows\Temp\failover.vbs"
delete __FileCreate
delete {parameter "_Script"}
createfile until __FileCreate
delete {parameter "_Script"}
sServices=Split("{parameter "_Services" of action}", ",")
for each x in sServices
StopService ".", """" & x & """", True
next
wscript.quit
Sub StopService(Computer, ServiceName, Wait)
Dim cimv2, oService, Result
'Get the WMI administration object
Set cimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
Computer & "\root\cimv2")
'Get the service object
Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'")
'Check base properties
If Not oService.Started Then
' the service is Not started
wscript.echo "The service " & ServiceName & " is Not started"
exit Sub
End If
If Not oService.AcceptStop Then
' the service does Not accept stop command
wscript.echo "The service " & ServiceName & " does Not accept stop command"
exit Sub
End If
'wscript.echo oService.getobjecttext_
'Stop the service
Result = oService.StopService
If 0 <> Result Then
wscript.echo "Stop " & ServiceName & " error: " & Result
exit Sub
End If
Do While oService.Started And Wait
'get the current service state
Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'")
wscript.echo now, "StopService", ServiceName, oService.Started, _
oService.State, oService.Status
Wscript.Sleep 200
Loop
End Sub
__FileCreate
move __createfile "{parameter "_Script"}"
waithidden cscript.exe "{parameter "_Script"}"
parameter "__ExitCode" = "{if exist exit code of action then exit code of action as string else "404"}"
if {parameter "__ExitCode" != "0"}
exit {parameter "__ExitCode"}
endif
delete __FileCreate
delete {parameter "_Script"}
with the success criteria of:
exit code of action != 0
Do you need all of the services to be stopped in a particular order, or do they just all need to be stopped?
I generally would recommend many smaller tasks, each one stopping a single service. They could be bundled into a baseline as @sbl mentions to take them all as a single action in a repeatable way.
In general, a single task or fixlet should do as little as possible and they should be grouped together in a multi-action group or baseline to be taken as a whole.