'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2007
'
' NAME:
'
' AUTHOR: DSI , TTC
' DATE : 05/08/2008
'
' COMMENT:
'
'==========================================================================
Dim strCredentials, arrCredentials, strUser, strPassword, strNamespace, strLocalComputer, strComputer, strService, objService
On Error Resume Next
Const WbemAuthenticationLevelPktPrivacy = 6
Const ForReading = 1
Function PingStatus(strComputer)
On Error Resume Next
strWorkstation = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strWorkstation & "\root\cimv2")
Set colPings = objWMIService.ExecQuery _
("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'")
For Each objPing In colPings
Select Case objPing.StatusCode
Case 0 PingStatus = "Success"
Case 11001 PingStatus = "Status code 11001 - Buffer Too Small"
Case 11002 PingStatus = "Status code 11002 - Destination Net Unreachable"
Case 11003 PingStatus = "Status code 11003 - Destination Host Unreachable"
Case 11004 PingStatus = _
"Status code 11004 - Destination Protocol Unreachable"
Case 11005 PingStatus = "Status code 11005 - Destination Port Unreachable"
Case 11006 PingStatus = "Status code 11006 - No Resources"
Case 11007 PingStatus = "Status code 11007 - Bad Option"
Case 11008 PingStatus = "Status code 11008 - Hardware Error"
Case 11009 PingStatus = "Status code 11009 - Packet Too Big"
Case 11010 PingStatus = "Status code 11010 - Request Timed Out"
Case 11011 PingStatus = "Status code 11011 - Bad Request"
Case 11012 PingStatus = "Status code 11012 - Bad Route"
Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired Transit"
Case 11014 PingStatus = _
"Status code 11014 - TimeToLive Expired Reassembly"
Case 11015 PingStatus = "Status code 11015 - Parameter Problem"
Case 11016 PingStatus = "Status code 11016 - Source Quench"
Case 11017 PingStatus = "Status code 11017 - Option Too Big"
Case 11018 PingStatus = "Status code 11018 - Bad Destination"
Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC"
Case 11050 PingStatus = "Status code 11050 - General Failure"
Case Else PingStatus = "Status code " & objPing.StatusCode & _
" - Unable to determine cause of failure."
End Select
Next
End Function
strNamespace = "root\cimv2"
Set objPassword = CreateObject("ScriptPW.Password")
Set objNetwork = CreateObject("Wscript.Network")
strLocalComputer = objNetwork.ComputerName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFileRead = objFSO.OpenTextFile("c:\HQ_DEV.TXT", ForReading)
strUser = InputBox("Enter Username","Username")
'WARNING PASSWORD IN CLEAR TEXT
strPassword = InputBox("Enter password","password")
Do Until objFileRead.AtEndOfStream
ToClean = objFileread.ReadLine
strComputer = Replace(ToClean, " ", "")
strPingstatus = ""
strPingstatus = PingStatus(strComputer)
If strPingStatus = "Success" Then
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objwbemLocator.ConnectServer _
(strComputer, strNamespace, strUser, strPassword)
objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy
' =====================================================================
'Step 4. List running services
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")
' =====================================================================
'Step 5. User enters service name to be restarted
'Enter the name of the service you wish to restart.
strserviceName= "TSM_ACCEPTOR_"
strService = strServiceName & strComputer
If strService = "" Then
WScript.Echo "No service name was given or you clicked Cancel"
WScript.Quit
End If
'Step 6. Restart service
RestartServices
End if
Loop
Sub RestartServices()
'Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("ASSOCIATORS OF {Win32_Service.Name='" & strService & "'} WHERE AssocClass=Win32_DependentService Role=Antecedent")
For Each objService in colServiceList
WScript.Echo "Stopping: " & objService.DisplayName
intResult = objService.StopService()
WScript.Echo "Result: " & intResult
Next
WScript.sleep 10000
Set colServiceList = objWMIService.ExecQuery("Select * FROM Win32_Service WHERE Name='" & strService & "'")
For Each objService in colServiceList
WScript.Echo "Stopping: " & objService.DisplayName
intResult = objService.StopService()
'Step 7. Echo confirmatiom message that service stopped
WScript.Echo "Result: " & intResult
WScript.Sleep 10000
intResult = objService.StartService()
'Step 8. Echo confirmatiom message that service started
WScript.Echo "Starting: " & objService.DisplayName
WScript.Echo "Result: " & intResult
Next
End Sub
' =====================================================================
' End
' =====================================================================