Link to home
Start Free TrialLog in
Avatar of dion_p1
dion_p1

asked on

Restart Service via Script?

I need to restart a windows service using vbs script the service name is "Papercut Application Server". Is there any way to do this via vbs script ?
Avatar of David Lee
David Lee
Flag of United States of America image

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
This will start a service.

strComputer = "ComputerName"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName='Papercut Application Server'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
      objItem.StartService
Next
Avatar of dion_p1
dion_p1

ASKER

Is there a way to stop it first?
ASKER CERTIFIED SOLUTION
Avatar of StuFox100
StuFox100
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial