Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Start Stop Service
 

Vbscript / Processes And Services / Start Stop Service

Start, stop or restart a service using WMI.


strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & " ootcimv2")

strService = "Spooler"

Set colListOfServices = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Service WHERE Name = '" & strService & "'")
For Each objService in colListOfServices

'Only act on service if not disabled
If NOT objService.StartMode = "Disabled" Then

 'Stop Service
 returnCode = objService.StopService()

WScript.Sleep 5000

 'Start Service
 returnCode = objService.StartService()

If returnCode <> 0 Then
'Test code below
Wscript.Echo "Error " & returnCode
End If

End If

Next





Please note that a disclaimer applies to any code on this page.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
     - General
     - Ms Office
     - Operating System
     - Processes And Services
          - Computer Service Properties
          - End Process
          - Running Process Properties
          - Start Stop Service
     - Text Processing
     - User Interaction
     - Web Servers