Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wildcards in string search 1

Status
Not open for further replies.

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.


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
 
If InStr(UCase(objService.DisplayName), "TRIM ") > 0 Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Works a treat - have a star!

Thanks a million,

M.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top