Follow us on Twitter

Have a question on something? Visit the forum for help.

NEW!! LazyNetworkAdmin Forums! Click -> here

 

Remotely Restart a Service PDF Print E-mail

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.




Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! Mixx! Free and Open Source Software News Google! Live! Facebook! StumbleUpon! TwitThis Joomla Free PHP
 
 

Sponsored Links