Avatar of syseng007
syseng007
 asked on

VB Script Experts...Need Help

I need to run the following script to query predominantly 2003 and minimal 2008 to query a service's state using local administrator ID SAAdmin. The reason why I need to use local administrator credentials it's because the servers reside in different domains. PLease help! Thank you.

'********************************************************************************
'* File:      ServiceState.vbs
'* Main Functions:  Extracts a list of computer names or IP addresses from a text  
'*                file and sends a PING to each to determine UP/DOWN state.
'*                Writes results to comma delimited text file named
'*                SERVICEResults.month.day.hour.minute.log listing host names or
'*                IP addresses and the status of each specified service.
'*
'* Required file: compname.txt containing a single column of host names or IP
'*                address with no white space in the same directory as this script.
'*
'********************************************************************************
 
 
Dim sDate
Dim strTime
Dim strDate
Dim strState
Dim strDataIn             'Input list from text file
Dim aryData                  'Array to hold input stream
Dim iCounter             'Iterative loop counter
dim strOUT                  'Output file
Dim oWshShell            'Windows shell script
Dim objFSO                  'Scripting File System
Dim objFile                  'Open text file
Dim strFilePath            'Path to current directory
Dim strServiceName      'Name of service to be checked
 
Set oWshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFilePath = objFSO.GetAbsolutePathName(".")
 
'Get Service Name
strServiceName = InputBox("Enter name of service...", "Service name input")
 
'Read file into a variable
strDataIn = f_r(strFilePath & "\compname.txt")
'Split into an array
aryData = Split(strDataIn,vbCrLf)
 
oWshShell.Popup Ubound(aryData) + 1 & " Hosts/Addresses in list." & Chr(13) & "Scan is underway.",2,"Notice",64
sDate = Date
strTime = Now
StrDate = DatePart("m",sDate) & "." & DatePart("d",sDate) & "." & Hour(strTime) & "." & Minute(strTime)
set strOUT = objFSO.CreateTextFile(strFilePath & "\SERVICEResults." & strDate & ".log")
 
strOUT.WriteLine strServiceName & " query results:"
strOUT.WriteBlankLines (2)
For iCounter = 0 to Ubound(aryData)
 aryData(iCounter) = Trim(aryData(iCounter)) ' clean "white space"
 
 if GetService(aryData(iCounter), strServiceName) then
      strOUT.Write aryData(iCounter) & ",Installed : " & strState & vbcrlf
 else
      strOUT.Write aryData(iCounter) & ",Service not present" & vbcrlf
 end if
Next
 
strOUT.Close
 
set strOUT = nothing
set objFSO = nothing
 
oWshShell.Popup "Scan processing complete.",5,"Notice",64
 
wscript.quit
 
 
'********************************************************************************
'* Function f_r(FilePath)
'*      
'*      Given the path to a file,  this function will return entire contents
'*
'********************************************************************************
 
Function f_r(FilePath)
 Dim FSO
 set FSO = CreateObject("Scripting.FileSystemObject")
 
  f_r = FSO.OpenTextFile(FilePath,1).ReadAll
 
End Function
 
 
 
 
'********************************************************************************
'* Function GetService(strComputer)
'*
'*      Returns True or False based on the status of the specified Service
'*  
'*
'********************************************************************************
 
Function GetService(strComputer, strSrvce)
 
On Error Resume Next
 
Dim objWMIService
Dim colListOfServices
Dim objService
 
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
    ("Select DisplayName,State from Win32_Service Where Name = '" & strSrvce & "'")
 
If Err.Number <> 0 Then
  GetService = "False"
  Err.Clear
 
Else
  For Each objService in colListOfServices
   GetService = "True"
   strState = objService.State
   
  Next
 
End If
 
End Function
VB Script

Avatar of undefined
Last Comment
RobSampson

8/22/2022 - Mon
SOLUTION
kevinhigg

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
RobSampson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy