mutley1
MIS
- Jul 24, 2003
- 909
Hi All,
apologies if this is a simple one but I have no experience with VB really. Please see the code below - what I want to know is can I use a wildcard in the string it is searching for. This example is using WMI and listing the service for TRIM CONTEXT WORKGROUP SERVER. I have several services containing TRIM so can wildcards be used in the quotes on the line
If ucase (objService.DisplayName) = "TRIM CONTEXT WORKGROUP SERVER"
so i can just search for anything containing TRIM or do i have to specify the exact text for each service?
Cheers,
M.
apologies if this is a simple one but I have no experience with VB really. Please see the code below - what I want to know is can I use a wildcard in the string it is searching for. This example is using WMI and listing the service for TRIM CONTEXT WORKGROUP SERVER. I have several services containing TRIM so can wildcards be used in the quotes on the line
If ucase (objService.DisplayName) = "TRIM CONTEXT WORKGROUP SERVER"
so i can just search for anything containing TRIM or do i have to specify the exact text for each service?
Cheers,
M.
Code:
'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************
Function Main()
On Error Resume Next
'Set the report output directory (end with a backslash) dir = "D:\TrimServicesAnalysis\"
'Set the text report file name
filename = "WorkgroupServiceStatus.txt"
'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream =
oFSO.OpenTextFile("D:\TrimServicesAnalysis\LISTWorkgroup.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine) 'close the data file oTextStream.Close
For Each strComputer In RemotePC
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
("Select * from Win32_Service")
For Each objService in colRunningServices
If ucase (objService.DisplayName) = "TRIM CONTEXT WORKGROUP SERVER"
Then
Report = Report & vbCrLf & "Computer " & strComputer & " reports service " & objService.DisplayName & " is " & objService.State
End If
Next
Next
If Not oFSO.FolderExists(dir) Then
oFSO.CreateFolder(dir)
End If
Set ts = oFSO.CreateTextFile (dir & filename, True) ts.write report
Main = DTSTaskExecResult_Success
End Function