'========================================================================== ' NAME: ' ' AUTHOR: Ed Wilson , MS ' DATE : 10/26/2003 who knows, that was a long time ago. ' ver. 2.0 2/1/2006 added opening of text files ' ver. 2.1 4/17/06 added input box and formatted text ' COMMENT: Connects to WMI and reads all classes in namespace. ' Then it checks file existance, and if requried writes to file. ' Then it parses the text file for a word, Memory for instance. ' displays all classes with the word Memory within it. ' Note as stands, search string is CASE insensitive. ' Re-formatted text, created subs, declared all veriables, and ' OPEN file once it is done saving the results. ' Uses inputBox function to promote ease of use. Uses vbNewLine '========================================================================== Option Explicit Dim strComputer 'target computer Dim wmiNS 'wmi name space Dim logFile, logFile2 'Text files Dim searchString 'string to search for Dim objFSO 'Filesystemobject Dim objFile, objFile2 'the file to work with Dim strNextLine 'line of text from readline Dim colItems 'collection returned by execQuery Dim objItem 'item from collection dim objSWbemServices 'connection into wmi Dim strTitle 'title for inputbox Dim strPrompt 'prompt for inputbox Dim strDefault 'default value for InputBox strTitle = "Search for WMI Classes" strPrompt = "Type in type of class to search for" &_ vbNewLine & "No quotes are needed" strDefault = "Process" strComputer = "." wmiNS = "\root\cimv2" LogFile = "C:\FSO\WMIclasses.txt" LogFile2 = "C:\FSO\WMIparsed.txt" Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 SearchString = InputBox(strPrompt,strTitle,strDefault) Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(LogFile) Then Set objFile = objFSO.OpenTextFile(LogFile, ForWriting) subWMI Else Set objFile = objFSO.CreateTextFile(LogFile) subWMI End If objFile.close If objFSO.FileExists(LogFile2) Then Set objFile2 = objFSO.OpenTextFile(LogFile2, ForWriting) Set objFile = objFSO.OpenTextFile(LogFile, ForReading) Do until objFile.AtEndOfStream strNextLine = objFile.Readline if InStr (1,strNextLine, SearchString, vbTextCompare)Then objFile2.WriteLine strNextLine End If Loop objFile.close objFile2.close Else Set objFile2 = objFSO.CreateTextFile(LogFile2) Set objFile = objFSO.OpenTextFile(LogFile, ForReading) Do until objFile.AtEndOfStream strNextLine = objFile.Readline if InStr (1, strNextLine, searchString, vbTextCompare)Then objFile2.WriteLine strNextLine End if Loop objFile.close objFile2.close End If subOpen WScript.Echo("all done") ' *** subs below *** Sub subWMI Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & wmiNS) Set colItems = objSWbemServices.SubclassesOf() For Each objItem In colItems objFile.WriteLine objItem.Path_.Path Next End Sub Sub subOpen Dim objshell Set objshell = CreateObject("wscript.shell") objshell.Run LogFIle2 End Sub