Remotely Restart a Service

By | May 5, 2006

Hey, did you ever need to restart a service remotely? Now you can!
This script will let you choose a computer and service to restart.

Copy and paste the following text into notepad and save it as a .vbs file.

———-COPY EVERYTHING BELOW THIS LINE———-

‘This script will s\restart a service remotly.
‘By Cheyenne Harden 1-18-06
‘____________________________________________________________

 

Option Explicit
Dim objWMIService, objItem, objService
Dim colListOfServices, strComputer, strService, strService2, intSleep, title
title = “Restart Service”
strComputer = inputbox (“Enter computer name here.”,title, “.”)
If strComputer > “” Then
strService2 = inputbox (“Enter service name here.”,title,”Tlntsvr”)

If strService2 > “” Then
strService = “‘” & strService2 & “‘”
intSleep = 15000

On Error Resume Next
‘ NB strService is case sensitive.

Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” _
& strComputer & “\root\cimv2”)
Set colListOfServices = objWMIService.ExecQuery _
(“Select * from Win32_Service Where Name =”_
& strService & ” “)
For Each objService in colListOfServices
objService.StopService()
WSCript.Sleep intSleep
objService.StartService()
Next
WScript.Echo “Your “& strService & ” service has re-started”
WScript.Quit
‘ End of Example WMI script to Start / Stop services
Else
Wscript.Quit
End If
Else
Wscript.Quit
End If
Wscript.Quit

 

———-COPY EVERYTHING ABOVE THIS LINE———-

Here is what you need to know to run this script:
1. Name of the computer you are targeting
2. Name of the service.

This information is provided “AS IS” with no warranty expressed or implied.

Leave a Reply

Your email address will not be published. Required fields are marked *