Generate Batch, JScript, KiXtart, Object Rexx, Perl, PowerShell, Python and VBScript code for WMI queries
31/07/2009 15:30<HEAD> <TITLE>WMI Code Generator</TITLE> <HTA:APPLICATION ID="WMIGen" VERSION="2.01" APPLICATIONNAME="WMI Code Generator" SCROLL="yes" SINGLEINSTANCE="yes" WINDOWSTATE="maximize" > </HEAD> <SCRIPT LANGUAGE="VBScript"> ' Variable to set filter for classes shown ' If True then all classes are shown ' If False then only WIN32_* classes are shown Dim blnShowAllClasses ' Internet Explorer object to contain MSDN help pages Dim objIEHelp Sub ButtonState( blnCodeButtonsEnabled ) If blnCodeButtonsEnabled Then CopyCodeButton.Disabled = True CopyCodeButton.Title = "" ClearCodeButton.Disabled = True ClearCodeButton.Title = "" CreateBatchCodeButton.Disabled = False CreateBatchCodeButton.Title = "Press this button to show the batch code that will display the properties and their values for the selected WMI class" CreateJScriptCodeButton.Disabled = False CreateJScriptCodeButton.Title = "Press this button to show the JScript code that will display the properties and their values for the selected WMI class" CreateKiXtartCodeButton.Disabled = False CreateKiXtartCodeButton.Title = "Press this button to show the KiXtart code that will display the properties and their values for the selected WMI class" CreatePerlCodeButton.Disabled = False CreatePerlCodeButton.Title = "Press this button to show the Perl code that will display the properties and their values for the selected WMI class" CreatePowerShellCodeButton.Disabled = False CreatePowerShellCodeButton.Title = "Press this button to show the PowerShell code that will display the properties and their values for the selected WMI class" CreatePythonCodeButton.Disabled = False CreatePythonCodeButton.Title = "Press this button to show the Python code that will display the properties and their values for the selected WMI class" CreateObjectRexxCodeButton.Disabled = False CreateObjectRexxCodeButton.Title = "Press this button to show the Obeject Rexx code that will display the properties and their values for the selected WMI class" CreateVBScriptCodeButton.Disabled = False CreateVBScriptCodeButton.Title = "Press this button to show the VBScript code that will display the properties and their values for the selected WMI class" Else CopyCodeButton.Disabled = False CopyCodeButton.Title = "Press this button to copy the generated code to the clipboard" ClearCodeButton.Disabled = False ClearCodeButton.Title = "Press this button to erase the generated code" CreateBatchCodeButton.Disabled = True CreateBatchCodeButton.Title = "" CreateJScriptCodeButton.Disabled = True CreateJScriptCodeButton.Title = "" CreateKiXtartCodeButton.Disabled = True CreateKiXtartCodeButton.Title = "" CreatePerlCodeButton.Disabled = True CreatePerlCodeButton.Title = "" CreatePowerShellCodeButton.Disabled = True CreatePowerShellCodeButton.Title = "" CreatePythonCodeButton.Disabled = True CreatePythonCodeButton.Title = "" CreateObjectRexxCodeButton.Disabled = True CreateObjectRexxCodeButton.Title = "" CreateVBScriptCodeButton.Disabled = True CreateVBScriptCodeButton.Title = "" End If End Sub Sub CheckUpdate( ) ' Change cursor to hourglass while checking for update Document.Body.Style.Cursor = "wait" strLatestVer = TextFromHTML( "https://www.robvanderwoude.com/updates/wmigen.txt" ) lenLatestVer = Len( strLatestVer ) If lenLatestVer = 4 Then strCurrentVer = WMIGen.Version If strLatestVer < strCurrentVer Then Update.InnerHTML = "<P>You seem to be using an invalid version (" & strCurrentVer _ & ") of the WMI Code Generator.<BR>The latest valid version is " _ & strLatestVer & " and it is available " _ & "<A HREF=""https://www.robvanderwoude.com/wmigen.html"">" _ & "<FONT COLOR=""Red"">here</FONT></A>.</P>" End If If strLatestVer > strCurrentVer Then Update.InnerHTML = "<P>You are using version " & strCurrentVer _ & " of the WMI Code Generator.<BR>An update to version " _ & strLatestVer & " is available " _ & "<A HREF=""https://www.robvanderwoude.com/wmigen.html"">" _ & "<FONT COLOR=""Red"">here</FONT></A>.</P>" End If End If ' Change cursor back to default Document.Body.Style.Cursor = "default" End Sub Sub CheckWindowSize( ) myWidth = Document.Body.ClientWidth smallBoxWidth = 20 largeBoxWidth = 45 If myWidth > 750 Then smallBoxWidth = 33 largeBoxWidth = 70 End If If myWidth > 1000 Then smallBoxWidth = 45 largeBoxWidth = 95 End If If myWidth > 1200 Then smallBoxWidth = 60 largeBoxWidth = 125 End If Code.Cols = largeBoxWidth ' Methods.Cols = smallBoxWidth ' Properties.Cols = smallBoxWidth End Sub Sub ClearCode( ) Code.Value = "" ButtonState True End Sub Sub CopyCode( ) strCode = Code.Value Document.ParentWindow.ClipboardData.SetData "text", strCode End Sub Sub CreateIEHelp( ) On Error Resume Next objIEHelp.Close On Error Goto 0 Set objIEHelp = Nothing Set objIEHelp = CreateObject( "InternetExplorer.Application" ) objIEHelp.Navigate "about:blank" objIEHelp.AddressBar = 1 objIEHelp.MenuBar = 1 objIEHelp.StatusBar = 1 objIEHelp.ToolBar = 1 objIEHelp.Top = 0 objIEHelp.Left = 0 objIEHelp.Width = 800 objIEHelp.Height = 600 objIEHelp.TheaterMode = 0 objIEHelp.Visible = 1 End Sub Function CreateLine( strProperty ) ' This subroutine will split up a string into separate words: ' "SCSILogicalUnit" will be converted to "SCSI Logical Unit" On Error Resume Next dim i, j, k, strPropDescr, strLowc, strCaps, strPad, chrA, chrB strPropDescr = strProperty strCaps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" strPad = " " strLowc = LCase( strCaps ) i = 0 Do i = i + 1 j = i + 1 If j >= Len( strPropDescr ) Then Exit Do chrA = Mid( strPropDescr, i, 1 ) chrB = Mid( strPropDescr, j, 1 ) If InStr( strLowc, chrA ) > 0 And InStr( strCaps, chrB ) > 0 Then strPropDescr = Left( strPropDescr, i ) & " " & Mid( strPropDescr, j ) i = i + 2 j = i + 1 End If Loop If Len( strPropDescr ) > 2 Then i = 0 Do i = i + 1 j = i + 1 k = i + 2 If k >= Len( strPropDescr ) Then Exit Do chrA = Mid( strPropDescr, i, 1 ) chrB = Mid( strPropDescr, j, 1 ) chrC = Mid( strPropDescr, k, 1 ) If InStr( strCaps, chrA ) > 0 And InStr( strCaps, chrB ) > 0 And InStr( strLowc, chrC ) > 0 Then strPropDescr = Left( strPropDescr, i ) & " " & Mid( strPropDescr, j ) i = i + 3 j = i + 1 k = i + 2 End If Loop End If CreateLine = Left( strPropDescr & strPad, 31 ) & ":" End Function Sub FillClassDropDown( ) ' Bubble sort algorithm found in Microsoft's Script Repository ' https://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1122.mspx Dim arrOptions( ) intSize = 0 ' Change cursor to hourglass while loading WMI class list Document.Body.Style.Cursor = "wait" Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root\cimv2" ) Set colClasses = objWMIService.SubClassesOf ' Store the list of classes in an array For Each objClass In colClasses If Left( objClass.Path_.Class, 6 ) = "Win32_" OR blnShowAllClasses Then ReDim Preserve arrOptions( intSize ) arrOptions( intSize ) = objClass.Path_.Class intSize = intSize + 1 End If Next ' Sort the classes For i = ( UBound( arrOptions ) - 1 ) to 0 Step -1 For j= 0 to i If UCase( arrOptions( j ) ) > UCase( arrOptions( j + 1 ) ) Then strHolder = arrOptions( j + 1 ) arrOptions( j + 1 ) = arrOptions( j ) arrOptions( j ) = strHolder End If Next Next ' Populate the classes list For i = 0 To UBound( arrOptions ) Set objNewOption = document.createElement( "OPTION" ) If CInt( i / 2 ) <> ( i / 2 ) Then objNewOption.style.backgroundcolor = "#F0F0F0" End If objNewOption.Text = arrOptions(i) If i = 0 Then objNewOption.Selected = True WMIClasses.options.Add( objNewOption ) Next ' Change cursor back to default Document.Body.Style.Cursor = "default" HandleClassChange End Sub Sub GetHelp( ) ' Check which class is selected For Each objOption In WMIClasses.options If objOption.Selected = True Then strClass = Trim( objOption.Text) End If Next ' Check which Property is selected, if any strMember = "" For Each objOption In Properties.options If objOption.Selected = True Then strMember = "+" & Trim( objOption.Text ) & "+property" End If Next ' Check which Method is selected, if any For Each objOption In Methods.options If objOption.Selected = True Then strMember = "+" & Trim( objOption.Text ) & "+method" End If Next ' Google search techniques learned from ' https://www.seroundtable.com/archives/015944.html strURLHelp = "https://www.google.com/search?q=" _ & strClass _ & strMember _ & "&site=msdn.microsoft.com&btnI=745&pws=0" On Error Resume Next objIEHelp.Navigate strURLHelp If Err.Number Then CreateIEHelp objIEHelp.Navigate strURLHelp End If On Error Goto 0 objIEHelp.Visible = 1 End Sub Sub HandleClassChange( ) Dim arrMethods( ), arrProperties( ) Dim intMethods, intProperties ' Purge the Methods list For Each objOption in Methods.options objOption.RemoveNode Next ReDim arrMethods( 0 ) intMethods = 0 ' Purge the Properties list For Each objOption in Properties.options objOption.RemoveNode Next ReDim arrProperties( 0 ) intProperties = 0 ' Change cursor to hourglass while loading the class' members lists Document.Body.Style.Cursor = "wait" For Each objOption In WMIClasses.Options If objOption.Selected = True Then strClass = objOption.Text Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" ) Set objClass = objWMIService.Get( strClass ) ' Store the list of methods in an array For Each objMethod In objClass.Methods_ ReDim Preserve arrMethods( intMethods ) arrMethods( intMethods ) = objMethod.Name intMethods = intMethods + 1 Next ' Store the list of properties in an array For Each objProperty In objClass.Properties_ ReDim Preserve arrProperties( intProperties ) arrProperties( intProperties ) = objProperty.Name intProperties = intProperties + 1 Next If IsArray( arrMethods ) Then ' Sort the methods list For i = ( UBound( arrMethods ) - 1 ) to 0 Step -1 For j= 0 to i If UCase( arrMethods( j ) ) > UCase( arrMethods( j + 1 ) ) Then strHolder = arrMethods( j + 1 ) arrMethods( j + 1 ) = arrMethods( j ) arrMethods( j ) = strHolder End If Next Next ' Populate the Methods list i = 0 For Each strOption in arrMethods Set objNewOption = document.createElement( "OPTION" ) If CInt( i / 2 ) <> ( i / 2 ) Then objNewOption.style.backgroundcolor = "#F0F0F0" End If objNewOption.Text = strOption Methods.options.Add( objNewOption ) i = i + 1 Next End If If IsArray( arrProperties ) Then ' Sort the properties list For i = ( UBound( arrProperties ) - 1 ) to 0 Step -1 For j= 0 to i If UCase( arrProperties( j ) ) > UCase( arrProperties( j + 1 ) ) Then strHolder = arrProperties( j + 1 ) arrProperties( j + 1 ) = arrProperties( j ) arrProperties( j ) = strHolder End If Next Next ' Populate the Properties list i = 0 For Each strOption in arrProperties Set objNewOption = document.createElement( "OPTION" ) If CInt( i / 2 ) <> ( i / 2 ) Then objNewOption.style.backgroundcolor = "#F0F0F0" End If objNewOption.Text = strOption Properties.options.Add( objNewOption ) i = i + 1 Next End if End If Next ' Change cursor back to default Document.Body.Style.Cursor = "default" Code.Value = "" ButtonState True End Sub Sub ShowBatchCode For Each objOption In WMIClasses.Options If objOption.Selected = True Then strClass = objOption.Text End If Next strCode = "@ECHO OFF" & vbCrLf _ & ":: WMI query to list all properties and values of the " _ & strClass & " class" & vbCrLf _ & ":: This batch file was generated using the WMI Code Generator, " _ & "Version " & WMIGen.Version & vbCrLf _ & ":: https://www.robvanderwoude.com/wmigen.html" & vbCrLf & vbCrLf _ & "IF ""%˜1""=="""" (" & vbCrLf _ & vbTab & "SET Node=%ComputerName%" & vbCrLf _ & ") ELSE (" & vbCrLf _ & vbTab & "SET Node=%˜1" & vbCrLf _ & ")" & vbCrLf & vbCrLf _ & "WMIC.EXE /Node:%Node% /Output:STDOUT Path " _ & strClass & " Get /Format:LIST" & vbCrLf Code.Value = strCode ButtonState False End Sub Sub ShowJScriptCode ' IsArray an Join() functionality "borrowed" from Scriptomatic 2.0 ' https://www.microsoft.com/downloads/details.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&DisplayLang=en For Each objOption In WMIClasses.Options If objOption.Selected = True Then strClass = objOption.Text End If Next Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" ) Set objClass = objWMIService.Get( strClass ) strCode = "// WMI query to list all properties and values of the " _ & strClass & " class" & vbCrLf _ & "// This JScript code was generated using the " _ & "WMI Code Generator, Version " & WMIGen.Version & vbCrLf _ & "// https://www.robvanderwoude.com/wmigen.html" & vbCrLf & vbCrLf _ & "var wbemFlagReturnImmediately = 0x10;" & vbCrLf _ & "var wbemFlagForwardOnly = 0x20;" & vbCrLf & vbCrLf _ & "objArgs = WScript.Arguments;" & vbCrLf _ & "if ( objArgs.length == 1 ) {" & vbCrLf _ & " var strComputer = objArgs[0]" & vbCrLf _ & "} else {" & vbCrLf _ & " var strComputer = "".""" & vbCrLf _ & "}" & vbCrLf & vbCrLf _ & "var objWMIService = GetObject( ""winmgmts://"" + " _ & "strComputer + ""/root/CIMV2"" );" & vbCrLf _ & "var colItems = objWMIService.ExecQuery( ""SELECT * FROM " _ & strClass & ", ""WQL"", wbemFlagReturnImmediately | " _ & "wbemFlagForwardOnly );" & vbCrLf & vbCrLf _ & "var enumItems = new Enumerator( colItems );" & vbCrLf _ & "for ( ; !enumItems.atEnd(); enumItems.moveNext( ) ) {" & vbCrLf _ & " var objItem = enumItems.item( );" & vbCrLf & vbCrLf For Each objProperty In objClass.Properties_ If objProperty.IsArray = True Then strCode = strCode & vbTab _ & "try { WScript.Echo( """ _ & CreateLine( objProperty.Name ) _ & " "" + ( objItem." _ & objProperty.Name _ & ".toArray( ) ).join( "","" ) ); }" & vbCrLf _ & vbTab & "catch( e ) { WScript.Echo( """ _ & CreateLine( objProperty.Name ) _ & " null"" ); }" Else strCode = strCode & vbTab _ & "WScript.Echo( """ _ & CreateLine( objProperty.Name ) _ & " "" + " _ & "objItem." & objProperty.Name _ & " );" End If strCode = strCode & vbCrLf Next strCode = strCode & vbTab & "WScript.Echo( """" );" & vbCrLf & "}" & vbCrLf Code.Value = strCode ButtonState False End Sub Sub ShowKiXtartCode For Each objOption In WMIClasses.Options If objOption.Selected = True Then strClass = objOption.Text End If Next Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" ) Set objClass = objWMIService.Get( strClass ) strCode = "; WMI query to list all properties and values of the " _ & strClass & " class" & vbCrLf _ & "; This KiXtart script was generated using the " _ & "WMI Code Generator, Version " & WMIGen.Version & vbCrLf _ & "; https://www.robvanderwoude.com/wmigen.html" & vbCrLf & vbCrLf _ & "Break On" & vbCrLf & vbCrLf _ & "If $computer = """"" & vbCrLf _ & vbTab & "$arrKixVer = Split( @Kix, ""."" )" & vbCrLf _ & vbTab & "$KiXVer = 100 * $arrKixVer[ 0 ] + $arrKixVer[ 1 ]" & vbCrLf _ & vbTab & "$computer = "".""" & vbCrLf _ & vbTab & "If $KixVer > 451" & vbCrLf _ & vbTab & vbTab & "$arrGetCommandLine = GetCommandLine( 1 )" & vbCrLf _ & vbTab & vbTab & "$LastArg = $arrGetCommandLine" _ & "[ UBound( $arrGetCommandLine ) ]" & vbCrLf _ & vbTab & vbTab & "If $LastArg <> ""@ScriptDir\@ScriptName""" & vbCrLf _ & vbTab & vbTab & vbTab & "$computer = $LastArg" & vbCrLf _ & vbTab & vbTab & "EndIf" & vbCrLf _ & vbTab & "EndIf" & vbCrLf _ & "EndIf" & vbCrLf & vbCrLf _ & "$objWMIService = GetObject( ""winmgmts://"" + " _ & "$computer + ""/root/CIMV2"" )" & vbCrLf _ & "$colItems = $objWMIService.ExecQuery( ""SELECT * FROM " _ & strClass & """, ""WQL"", 48 )" & vbCrLf & vbCrLf _ & "For Each $objItem In $colItems" & vbCrLf For Each objProperty In objClass.Properties_ strCode = strCode & vbTab & "? """ _ & CreateLine( objProperty.Name ) & " "" + " If objProperty.IsArray = True Then strCode = strCode & "Join( " End If strCode = strCode & "$objItem." & objProperty.Name If objProperty.IsArray = True Then strCode = strCode & ", "","" )" End If strCode = strCode & vbCrLf Next strCode = strCode & vbTab & "?" & vbCrLf & "Next" & vbCrLf & vbCrLf & "Quit" & vbCrLf Code.Value = strCode ButtonState False End Sub Sub ShowObjectRexxCode ' Based on the Rexx script samples found at the Script Repository: ' https://www.microsoft.com/technet/scriptcenter/scripts/rexx/default.mspx?mfr=true ' Tested with Open Object Rexx: https://www.oorexx.org/ For Each objOption In WMIClasses.Options If objOption.Selected = True Then strClass = objOption.Text End If Next Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" ) Set objClass = objWMIService.Get( strClass ) strCode = "/*" & vbCrLf _ & "WMI query to list all properties and values of the " _ & strClass & " class" & vbCrLf _ & "This Open Object Rexx script was generated using the " _ & "WMI Code Generator, Version " & WMIGen.Version & vbCrLf _ & "https://www.robvanderwoude.com/wmigen.html" & vbCrLf _ & "*/" & vbCrLf & vbCrLf _ & "Parse Upper Arg strComputer ." & vbCrLf _ & "If strComputer = """" Then strComputer = "".""" & vbCrLf & vbCrLf _ & "objWMIService = .OLEObject˜GetObject" _ & "( ""winmgmts://""||strComputer||""/root/CIMV2"" )" & vbCrLf & vbCrLf _ & "Do objItem Over objWMIService˜ExecQuery" _ & "( ""Select * from " & strClass & """ )" & vbCrLf For Each objProperty In objClass.Properties_ strCode = strCode & vbTab & "Say """ _ & CreateLine( objProperty.Name ) & " ""||" If objProperty.IsArray = True Then strCode = strCode & "Translate( " End If strCode = strCode & "objItem˜" & objProperty.Name If objProperty.IsArray = True Then strCode = strCode & ", "","", ""0D0A""x )" End If strCode = strCode & vbCrLf Next strCode = strCode & vbTab & "Say" & vbCrLf & "End" & vbCrLf Code.Value = strCode ButtonState False End Sub Sub ShowPerlCode For Each objOption In WMIClasses.Options If objOption.Selected = True Then strClass = objOption.Text End If Next Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" ) Set objClass = objWMIService.Get( strClass ) strCode = "#! perl" & vbCrLf & vbCrLf _ & "# WMI query to list all properties and values of the " _ & strClass & " class" & vbCrLf _ & "# This Perl script was generated using the " _ & "WMI Code Generator, Version " & WMIGen.Version & vbCrLf _ & "# https://www.robvanderwoude.com/wmigen.html" & vbCrLf & vbCrLf _ & "use Win32::OLE( 'in' );" & vbCrLf & vbCrLf _ & "use constant wbemFlagReturnImmediately => 0x10;" & vbCrLf _ & "use constant wbemFlagForwardOnly => 0x20;" & vbCrLf & vbCrLf _ & "if ( $ARGV[0] ) {" & vbCrLf _ & vbTab & "$computer = $ARGV[0];" & vbCrLf _ & "} else {" & vbCrLf _ & vbTab & "$computer = ""."";" & vbCrLf _ & "}" & vbCrLf & vbCrLf _ & "my $objWMIService = Win32::OLE->GetObject" _ & "( ""winmgmts://$computer/root/CIMV2"" )" _ & " or die ""WMI connection failed.\n"";" & vbCrLf _ & "my $colItems = $objWMIService->ExecQuery( ""SELECT * FROM " _ & strClass & """, ""WQL"", " _ & "wbemFlagReturnImmediately | wbemFlagForwardOnly );" & vbCrLf & vbCrLf _ & "foreach my $objItem ( in $colItems ) {" & vbCrLf For Each objProperty In objClass.Properties_ strCode = strCode & vbTab & "print """ _ & CreateLine( objProperty.Name ) & " "" . " If objProperty.IsArray = True Then strCode = strCode & "join( "","", ( in " End If strCode = strCode & "$objItem->{ " & objProperty.Name & " }" If objProperty.IsArray = True Then strCode = strCode & " ) )" End If strCode = strCode & " . ""\n"";" & vbCrLf Next strCode = strCode & vbTab & "print ""\n"";" & vbCrLf & "}" & vbCrLf Code.Value = strCode ButtonState False End Sub Sub ShowPowerShellCode For Each objOption In WMIClasses.Options If objOption.Selected = True Then strClass = objOption.Text End If Next Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" ) Set objClass = objWMIService.Get( strClass ) strCode = "# WMI query to list all properties and values of the " _ & strClass & " class" & vbCrLf _ & "# This PowerShell script was generated using the " _ & "WMI Code Generator, Version " & WMIGen.Version & vbCrLf _ & "# https://www.robvanderwoude.com/wmigen.html" & vbCrLf & vbCrLf _ & "param( [string]$strComputer = ""."" )" & vbCrLf & vbCrLf _ & "$colItems = get-wmiobject -class """ & strClass _ & """ -namespace ""root\CIMV2"" -computername $strComputer" & vbCrLf & vbCrLf _ & "foreach ($objItem in $colItems) {" & vbCrLf For Each objProperty In objClass.Properties_ strCode = strCode & vbTab & "write-host """ _ & CreateLine( objProperty.Name ) & """ " _ & "$objItem." & objProperty.Name & vbCrLf Next strCode = strCode & vbTab & "write-host" & vbCrLf & "}" & vbCrLf Code.Value = strCode ButtonState False End Sub Sub ShowPythonCode ' Python code based on Scriptomatic 2.0 generated code ' https://www.microsoft.com/technet/scriptcenter/tools/scripto2.mspx For Each objOption In WMIClasses.Options If objOption.Selected = True Then strClass = objOption.Text End If Next Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" ) Set objClass = objWMIService.Get( strClass ) strCode = "#! python" & vbCrLf & vbCrLf _ & "# WMI query to list all properties and values of the " _ & strClass & " class" & vbCrLf _ & "# This Python script was generated using the " _ & "WMI Code Generator, Version " & WMIGen.Version & vbCrLf _ & "# https://www.robvanderwoude.com/wmigen.html" & vbCrLf & vbCrLf _ & "import win32com.client" & vbCrLf & vbCrLf _ & "strComputer = "".""" & vbCrLf & vbCrLf _ & "objWMIService = win32com.client.Dispatch" _ & "( ""WbemScripting.SWbemLocator"" )" & vbCrLf _ & "objSWbemServices = objWMIService.ConnectServer" _ & "( strComputer, ""root/cimv2"" )" & vbCrLf _ & "colItems = objSWbemServices.ExecQuery( ""SELECT * FROM " _ & strClass & """ )" & vbCrLf & vbCrLf _ & "for objItem in colItems:" & vbCrLf For Each objProperty In objClass.Properties_ If objProperty.IsArray = True Then strCode = strCode _ & vbTab & "strList = "" """ & vbCrLf _ & vbTab & "try:" & vbCrLf _ & vbTab & vbTab & "for objElem in objItem." _ & objProperty.Name & " :" & vbCrLf _ & vbTab & vbTab & vbTab _ & "strList = strList + `objElem` + "",""" & vbCrLf _ & vbTab & "except:" & vbCrLf _ & vbTab & vbTab & "strList = strList + 'null'" & vbCrLf _ & vbTab & "print """ _ & CreateLine( objProperty.Name ) & """ + strList" & vbCrLf Else strCode = strCode _ & vbTab & "if objItem." & objProperty.Name _ & " != None:" & vbCrLf _ & vbTab & vbTab & "print """ _ & CreateLine( objProperty.Name ) & " "" + `objItem." _ & objProperty.Name & "`" & vbCrLf End If Next Code.Value = strCode ButtonState False End Sub Sub ShowVBScriptCode ' IsArray an Join() functionality "borrowed" from Scriptomatic 2.0 ' https://www.microsoft.com/downloads/details.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&DisplayLang=en For Each objOption In WMIClasses.Options If objOption.Selected = True Then strClass = objOption.Text End If Next Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" ) Set objClass = objWMIService.Get( strClass ) strCode = "' WMI query to list all properties and values of the " _ & strClass & " class" & vbCrLf _ & "' This VBScript code was generated using the " _ & "WMI Code Generator, Version " & WMIGen.Version & vbCrLf _ & "' https://www.robvanderwoude.com/wmigen.html" & vbCrLf & vbCrLf _ & "On Error Resume Next" & vbCrLf & vbCrLf _ & "Const wbemFlagReturnImmediately = &h10" & vbCrLf _ & "Const wbemFlagForwardOnly = &h20" & vbCrLf & vbCrLf _ & "If WScript.Arguments.UnNamed.Count = 1 Then" & vbCrLf _ & vbTab & "strComputer = WScript.Arguments.UnNamed(1)" & vbCrLf _ & "Else" & vbCrLf _ & vbTab & "strComputer = "".""" & vbCrLf _ & "End If" & vbCrLf & vbCrLf _ & "Set objWMIService = GetObject( ""winmgmts://"" & " _ & "strComputer & ""/root/CIMV2"" )" & vbCrLf _ & "Set colInstances = objWMIService.ExecQuery( ""SELECT * FROM " _ & strClass & """, ""WQL"", " _ & "wbemFlagReturnImmediately + wbemFlagForwardOnly )" & vbCrLf & vbCrLf _ & "For Each objInstance In colInstances" & vbCrLf For Each objProperty In objClass.Properties_ strCode = strCode & vbTab & "WScript.Echo """ _ & CreateLine( objProperty.Name ) & " "" & " If objProperty.IsArray = True Then strCode = strCode & "Join( " End If strCode = strCode & "objInstance." & objProperty.Name If objProperty.IsArray = True Then strCode = strCode & ", "","" )" End If strCode = strCode & vbCrLf Next strCode = strCode & vbTab & "WScript.Echo" & vbCrLf & "Next" & vbCrLf Code.Value = strCode ButtonState False End Sub Function TextFromHTML( URL ) ' Basic routine borrowed from https://dev.remotenetworktechnology.com/wsh/rubegoldberg.htm ' Improved wait-until-ready routine for HTAs by McKirahan on ' https://support.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.scripting.scriptlets&tid=be461ec2-b444-440c-8155-ad0e8e839ca6&lang=en&cr=US&sloc=en-us&p=1 Set objIE = CreateObject( "InternetExplorer.Application" ) objIE.Navigate URL While objIE.Busy Wend TextFromHTML = objIE.Document.Body.InnerText objIE.Quit End Function Sub Window_Onload AppVersion.InnerHTML = WMIGen.Version ButtonState True FillClassDropDown CheckWindowSize( ) CheckUpdate( ) CreateIEHelp( ) objIEHelp.Visible = 0 End Sub Sub Window_Onunload objIEHelp.Quit Set objIEHelp = Nothing End Sub </SCRIPT> <BODY STYLE="font:12 pt arial; color:white; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#000000', EndColorStr='#FFFFFF')" OnResize="CheckWindowSize()"> <DIV ALIGN="Center"> <SPAN ID="Update"> </SPAN> <TABLE BORDER="0" CELLSPACING="10"> <TR ALIGN="Center"> <TH COLSPAN="2" TITLE="Select a WMI class from this drop-down list and press one of the 'Create ... Code' buttons to show the code for the selected WMI query in the lower text area" ALIGN="Left">Select a WMI Class:</TH> </TR> <TR ALIGN="Center"> <TD COLSPAN="2" TITLE="Select a WMI class from this drop-down list and press one of the 'Create ... Code' buttons to show the code for the selected WMI query in the lower text area"><SELECT OnChange="HandleClassChange" NAME="WMIClasses" SIZE="6" STYLE="width: 100%"></SELECT></TH> </TR> <TR ALIGN="Center"> <TH TITLE="This list shows the available properties for the selected WMI class" ALIGN="Left">Properties:</TH> <TH TITLE="This list shows the available methods for the selected WMI class" ALIGN="Left">Methods:</TH> </TR> <TR ALIGN="Center"> <TD STYLE="width: 50%"><SELECT NAME="Properties" TITLE="This list shows the available properties for the selected WMI class" SIZE="6" STYLE="width: 100%"></SELECT></TD> <TD STYLE="width: 50%"><SELECT NAME="Methods" TITLE="This list shows the available methods for the selected WMI class" SIZE="6" STYLE="width: 100%"></SELECT></TD> </TR> <TR ALIGN="Center"> <TH TITLE="After pressing a 'Create ... Code' button, the generated code to display the available properties and their values for the selected WMI class will be shown here" ALIGN="Left">Code:</TH> <TH ALIGN="Right"><INPUT ID="GetHelpButton" OnClick="GetHelp" TYPE="submit" VALUE=" Help " TITLE="Press this button to search and open the relevant MSDN page for the selected class, method and/or property"></TH> </TR> <TR ALIGN="Center"> <TD COLSPAN="2"><TEXTAREA NAME="Code" ROWS="20" COLS="70" READONLY TITLE="After pressing a 'Create ... Code' button, the generated code to display the available properties and their values for the selected WMI class will be shown here"></TEXTAREA></TD> </TR> <TR ALIGN="Center"> <TD COLSPAN="2"> <TABLE BORDER="0" CELLSPACING="10"> <TR> <TD><INPUT ID="CreatePowerShellCodeButton" OnClick="ShowPowerShellCode" TYPE="submit" VALUE=" Create PowerShell Code " TITLE="Press this button to show the PowerShell code that will display the properties and their values for the selected WMI class"></TD> <TD><INPUT ID="CreateVBScriptCodeButton" OnClick="ShowVBScriptCode" TYPE="submit" VALUE=" Create VBScript Code " TITLE="Press this button to show the VBScript code that will display the properties and their values for the selected WMI class"></TD> </TR> <TR> <TD><INPUT ID="CreateKiXtartCodeButton" OnClick="ShowKiXtartCode" TYPE="submit" VALUE=" Create KiXtart Code " TITLE="Press this button to show the KiXtart code that will display the properties and their values for the selected WMI class"></TD> <TD><INPUT ID="CreateJScriptCodeButton" OnClick="ShowJScriptCode" TYPE="submit" VALUE=" Create JScript Code " TITLE="Press this button to show the JScript code that will display the properties and their values for the selected WMI class"></TD> </TR> <TR> <TD><INPUT ID="CreateBatchCodeButton" OnClick="ShowBatchCode" TYPE="submit" VALUE=" Create Batch Code " TITLE="Press this button to show the batch code that will display the properties and their values for the selected WMI class"></TD> <TD><INPUT ID="CreateObjectRexxCodeButton" OnClick="ShowObjectRexxCode" TYPE="submit" VALUE="Create Object Rexx Code" TITLE="Press this button to show the Object Rexx code that will display the properties and their values for the selected WMI class"></TD> </TR> <TR> <TD><INPUT ID="CreatePerlCodeButton" OnClick="ShowPerlCode" TYPE="submit" VALUE=" Create Perl Code " TITLE="Press this button to show the Perl code that will display the properties and their values for the selected WMI class"></TD> <TD><INPUT ID="CreatePythonCodeButton" OnClick="ShowPythonCode" TYPE="submit" VALUE=" Create Python Code " TITLE="Press this button to show the Python code that will display the properties and their values for the selected WMI class"></TD> </TR> <TR> <TD><INPUT ID="ClearCodeButton" OnClick="ClearCode" TYPE="submit" VALUE=" Clear Code " TITLE="Press this button to erase the generated code"></TD> <TD><INPUT ID="CopyCodeButton" OnClick="CopyCode" TYPE="submit" VALUE=" Copy Code to Clipboard " TITLE="Press this button to copy the generated code to the clipboard"></TD> </TR> </TABLE> </TD> </TR> </TABLE> <P><FONT COLOR="#000000">WMI Code Generator, Version <SPAN ID="AppVersion">0.00</SPAN><BR> <FONT SIZE="-1">© 2006 - 2008, Rob van der Woude<BR> <A HREF="https://www.robvanderwoude.com/" TARGET="_blank"><FONT COLOR="Red">https://www.robvanderwoude.com</FONT></A></FONT></FONT></P> <P><FONT COLOR="#000000" SIZE="-1">Based on the Microsoft TechNet ScriptCenter article <A HREF="https://www.microsoft.com/technet/scriptcenter/resources/guiguy/default.mspx" TARGET="_blank"><FONT COLOR="Red">Scripting Eye for the GUI Guy</FONT></A>.<BR> Created With help from the Scripting Guys' <A HREF="https://www.microsoft.com/technet/scriptcenter/tools/scripto2.mspx" TARGET="_blank"><FONT COLOR="Red">Scriptomatic 2.0</FONT></A> and <A HREF="https://www.microsoft.com/downloads/details.aspx?FamilyId=231D8143-F21B-4707-B583-AE7B9152E6D9&displaylang=en" TARGET="_blank"><FONT COLOR="Red">HTA Helpomatic</FONT></A> tools, and Adersoft's <A HREF="https://www.htaedit.com/" TARGET="_blank"><FONT COLOR="Red">HTAEdit</FONT></A>.<BR> Help search function based on <A HREF="https://www.google.com/" TARGET="_blank"><FONT COLOR="Red">Google Search</FONT></A> and completed with help from <A HREF="https://www.seroundtable.com/archives/015944.html" TARGET="_blank"><FONT COLOR="Red">Search Engine Roundtable</FONT></A>.</FONT></P> </DIV> </BODY> </HTML>
———
Back