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


=======


‘============================================================================================
‘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
             objTextFile.Write(txt)
txt =  “==============” & 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 UCase (objService.name)=sService then
   strServiceList=”Service installed”
   Exit For
   Else
   strServiceList=”Service Not installed”
   End if
   Next
 else
      strServiceList=”System Not Reacheable”
      Err.Clear
   End If


  
     txt =  strComputer & vbtab  & vbtab  & strServiceList & vbcrlf
     objTextFile.Write(txt)
     ‘WScript.Echo txt
             


End IF
Loop
objTextFile.Close
oFile.Close
Else
WScript.Echo “Create a input file was not there.”
End If
 


=============================================================


Hope this would be helpful


Sudheesh Narayanaswamy

Comments (0)

Skip to main content