Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Start And Stop A Service
 

Vbscript / Operating System / Start And Stop A Service

Start or stop a Windows service on the specified computer.


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
          - Add Remove Windows Server 2003 Components
          - Add Remove Windows Vista Components
          - Add Remove Windows Xp Components
          - Autologon And Runonce
          - Change Display Resolution
          - Change Location I386 Setup Files
          - Change Offline Folder Cache Location
          - Dell Bios Set Boot Device Order
          - Dell Bios Set Configuration Settings
          - Dell Bios View Configuration Settings
          - Dell Bios View Device Boot Order
          - Disable Vista User Account Control
          - Enumerate Cd Drives
          - Enumerate Computer Drives
          - Enumerate Disk Volumes
          - Enumerate Registry Keys
          - Flush Remote Dns Cache
          - Get Machine Hardware Model
          - Read Registry Key
          - Rename Computer
          - Rename Dell Machine By Service Tag
          - Set Internet Explorer Homepage
          - Set Random Desktop Wallpaper On Startup
          - Start And Stop A Service
          - Windows Login Timer
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers