Script to check if a service is installed or not in a group of systems


This is a script to check if a service is installed or not in a group of systems.  



'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 (Name of service in uppercase)
'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 = "CCMEXEC"
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 Status" & vbcrlf
txt =  "==============" & vbtab & vbtab  & "================" & vbcrlf

Do While Not oFile.AtEndOfStream
    sText = oFile.ReadLine
      If Trim(sText) <> "" Then
       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 UCase ( then
   strServiceList="Service installed"
   Exit For
   strServiceList="Service Not installed"
   End if
      strServiceList="System Not Reacheable"
   End If

     txt =  strComputer & vbtab  & vbtab  & strServiceList & vbcrlf
     'WScript.Echo txt

End IF
WScript.Echo "Create a input file was not there."
End If


Hope this would be helpful

Sudheesh Narayanaswamy

Comments (0)

Skip to main content