This script will help to check if the srevice is avilable or not in a group of system
'============================================================================================
'Script Written by Sudheesh Narayanaswamy
'This can be used to check if the srevice is avilable or not in a group of system
'Create a file called input.txt (location speiced in strFile) with computer name of the system each line having one server name
'Name the service which you want to check in the Varable sService (Disaply Name of service)
'The out file will be the loaction specified in the strReport variable
'==============================================================================================
Option Explicit
On Error Resume Next
const strReport = "c:\TEST\OUTPUT.txt"
const sFile = "C:\TEST\INPUT.txt"
const sService = "XXXXXXXXXXXXXXXXXX"
Dim objWMIService, objItem, colItems
Dim colListOfServices,strServiceList,objService
Dim strDriveType, strDiskSize, txt
Dim oFSO, oFile, sText,strComputer
Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim objFSO,objTextFile
Set objFSO = createobject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(strReport)
strServiceList="Service Not installed"
If oFSO.FileExists(sFile) Then
Set oFile = oFSO.OpenTextFile(sFile, 1)
txt = "Computer Name" & vbtab & vbtab &"Service Name" & vbtab & vbtab & "Service Status" & vbcrlf
objTextFile.Write(txt)
txt = "==============" & vbtab & vbtab & "==============" & vbtab & vbTab & "================" & vbcrlf
objTextFile.Write(txt)
Do While Not oFile.AtEndOfStream
sText = oFile.ReadLine
If Trim(sText) <> "" Then
strComputer=sText
txt=" "
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service ")
If Err = 0 Then
' WMI and VBScript loop
For Each objService in colListOfServices
If objService.DisplayName=sService1 then
txt=""
strServiceList = objService.DisplayName & VbTab & objService.State
txt = strComputer & vbtab & vbtab & strServiceList & vbcrlf
objTextFile.Write(txt)
End If
Next
else
strServiceList="System Not Reacheable"
Err.Clear
End If
End IF
Loop
objTextFile.Close
oFile.Close
Else
WScript.Echo "Create a input file was not there."
End If
Hope this helps
'============================================================================================
'Script Written by Sudheesh Narayanaswamy
'This can be used to check if the srevice is avilable or not in a group of system
'Create a file called input.txt (location speiced in strFile) with computer name of the system each line having one server name
'Name the service which you want to check in the Varable sService (Disaply Name of service)
'The out file will be the loaction specified in the strReport variable
'==============================================================================================
Option Explicit
On Error Resume Next
const strReport = "c:\TEST\OUTPUT.txt"
const sFile = "C:\TEST\INPUT.txt"
const sService = "XXXXXXXXXXXXXXXXXX"
Dim objWMIService, objItem, colItems
Dim colListOfServices,strServiceList,objService
Dim strDriveType, strDiskSize, txt
Dim oFSO, oFile, sText,strComputer
Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim objFSO,objTextFile
Set objFSO = createobject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(strReport)
strServiceList="Service Not installed"
If oFSO.FileExists(sFile) Then
Set oFile = oFSO.OpenTextFile(sFile, 1)
txt = "Computer Name" & vbtab & vbtab &"Service Name" & vbtab & vbtab & "Service Status" & vbcrlf
objTextFile.Write(txt)
txt = "==============" & vbtab & vbtab & "==============" & vbtab & vbTab & "================" & vbcrlf
objTextFile.Write(txt)
Do While Not oFile.AtEndOfStream
sText = oFile.ReadLine
If Trim(sText) <> "" Then
strComputer=sText
txt=" "
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service ")
If Err = 0 Then
' WMI and VBScript loop
For Each objService in colListOfServices
If objService.DisplayName=sService1 then
txt=""
strServiceList = objService.DisplayName & VbTab & objService.State
txt = strComputer & vbtab & vbtab & strServiceList & vbcrlf
objTextFile.Write(txt)
End If
Next
else
strServiceList="System Not Reacheable"
Err.Clear
End If
End IF
Loop
objTextFile.Close
oFile.Close
Else
WScript.Echo "Create a input file was not there."
End If
Hope this helps
No comments:
Post a Comment