Option Explicit Dim arrClasses( ), arrNameSpaces( ) Dim blnRC, blnRecursive Dim intRC, intSize, intValid, i, j, k dim objNameSpace, objNewOption Dim strHolder, strNameSpace blnRC = False blnRecursive = True intRC = 0 With WScript.Arguments intValid = 0 If .Named.Exists( "NR" ) Then intValid = intValid + 1 blnRC = True End If If .Named.Exists( "RC" ) Then intValid = intValid + 1 blnRC = True End If Select Case .Unnamed.Count Case 0 strNameSpace = "root" Case 1 strNameSpace = .Unnamed(0) If Left( LCase( strNameSpace ), 4 ) <> "root" Then If InStr( strNameSpace, "?" ) < 1 Then WScript.Echo "Error: invalid namespace """ & strNameSpace & """" End If Syntax End If intValid = intValid + 1 Case Else Syntax End Select If intValid <> .Count Then Syntax End With intSize = 0 ReDim Preserve arrNameSpaces(0) arrNameSpaces(0) = strNameSpace If Not WScript.Arguments.Named.Exists( "NR" ) Then ' Get a list of available namespaces EnumNameSpaces( arrNameSpaces(0) ) ' Sort the array of namespaces If UBound( arrNameSpaces ) > 1 Then For i = UBound( arrNameSpaces ) - 1 To 0 Step -1 For j= 0 to i k = j + 1 If UCase( arrNameSpaces(j) ) > UCase( arrNameSpaces(k) ) Then strHolder = arrNameSpaces(k) arrNameSpaces(k) = arrNameSpaces(j) arrNameSpaces(j) = strHolder End If Next Next End If End If ' List the classes for each namespace For i = 0 To UBound( arrNameSpaces ) ListClasses( arrNameSpaces(i) ) Next If blnRC Then WScript.Quit intRC Sub EnumNameSpaces( myNameSpace ) Dim colNameSpaces, intSize, objNameSpace, objWMIService intSize = UBound( arrNameSpaces ) On Error Resume Next Set objWMIService = GetObject ( "winmgmts:{impersonationLevel=impersonate}//./" & myNameSpace ) If Err Then WScript.Echo "WMI Error #" & Err.Number & ": " & Err.Description Syntax End If Set colNameSpaces = objWMIService.InstancesOf( "__NAMESPACE" ) For Each objNameSpace In colNameSpaces intSize = UBound( arrNameSpaces ) + 1 ReDim Preserve arrNameSpaces( intSize ) arrNameSpaces( intSize ) = myNameSpace & "/" & objNameSpace.Name EnumNameSpaces myNameSpace & "/" & objNameSpace.Name Next On Error Goto 0 End Sub Sub ListClasses( myNameSpace ) Dim colClasses, intSize, i, j, k, objClass, objWMIService, strHolder If myNameSpace = "root" Then Exit Sub Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}" & myNameSpace ) If Err Then MsgBox "Could not connect to " & myNameSpace, vbOKOnly, "NameSpace Error" WScript.Quit 1 End If Set colClasses = objWMIService.SubClassesOf If Err Then MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly, "Error" WScript.Quit 1 End If ' Store the list of classes in an array intSize = 0 For Each objClass In colClasses ReDim Preserve arrClasses( intSize ) arrClasses( intSize ) = objClass.Path_.Class intSize = intSize + 1 intRC = intRC + 1 Next If IsArray( arrClasses ) Then If UBound( arrClasses ) > 1 Then ' Sort the classes For i = ( UBound( arrClasses ) - 1 ) To 0 Step -1 For j= 0 to i k = j + 1 If UCase( arrClasses(j) ) > UCase( arrClasses(k) ) Then strHolder = arrClasses(k) arrClasses(k) = arrClasses(j) arrClasses(j) = strHolder End If Next Next End if ' Display the classes list For i = 0 To UBound( arrClasses ) WScript.Echo myNameSpace & ":" & arrClasses(i) Next End If End Sub Sub Syntax Dim strMsg strMsg = vbCrLf _ & "ListWMIClasses.vbs, Version 3.01" _ & vbCrLf _ & "List all WMI classes available in the specified namespace" _ & vbCrLf & vbCrLf _ & "Usage: CSCRIPT //NoLogo LISTWMICLASSES.VBS [ namespace ] [ /NR ] [ /RC ]" _ & vbCrLf & vbCrLf _ & "Where: ""namespace"" is the WMI namespace to be queried (default: ""root"")" _ & vbCrLf _ & " /NR do not recurse through namespaces" _ & vbCrLf _ & " /RC returns total number of classes found in return code" _ & vbCrLf & vbCrLf _ & "Written by Rob van der Woude" _ & vbCrLf _ & "http://www.robvanderwoude.com" WScript.Echo strMsg If blnRC Then WScript.Quit 0 Else WScript.Quit 1 End If End Sub