NorfiPC
Aplicaciones HTA

Generador de Códigos de WMI, aplicación en formato HTA

Código para crear WMI Code Generator, que permite obtener códigos para crear archivos batch o scripts, para obtener información de la consola de WMI de Windows.
Comparto en esta página el código para crear una aplicación en formato HTA llamada WMI Code Generator.
La página HTA así creada funciona como una aplicación, con la que se pueden generar código en varios formatos, para crear archivos batch, scripts en formato VBS, que permiten obtener información de WMIC (Consola de Windows Management Instrumentation).
Para crear la aplicación solo es necesario copiar y pegar el código en un archivo de texto plano y guardarlo con la extensión de archivo .HTA.
El código se puede editar y personalizar completamente para cambiar la apariencia de la aplicación.
La aplicación cuya versión es la 5.10, fue creada por Rob van der Woude, desde cuya web se puede descargar una versión más reciente en un archivo ejecutable.


Código para crear WMI Code Generator

<html>
<head>
<title>WMI Code Generator</title>
<HTA:APPLICATION 
	ID="WMIGen"
	VERSION="5.10"
	APPLICATIONNAME="WMI Code Generator"
	SCROLL="yes"
	SINGLEINSTANCE="yes"
	WINDOWSTATE="maximize"
>
<style type="text/css">
<!--
a { color: blue; }
p { color: black; font-size: 80%; }
.Button { width: 12em; margin: 3px 1em 3px 1em; }
.Red { color: red; }
.White { color: white; }
-->
</style>
</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
' Command line switch /WIN32 sets variable to False
Dim blnShowAllClasses
blnShowAllClasses = True

' Variable to set filter for Win32_Perf* classes
' If True then the Win32_Perf* classes are included
' If False then the Win32_Perf* classes are excluded
' Command line switch /NOPERF sets variable to False
Dim blnShowPerfClasses
blnShowPerfClasses = True

' Internet Explorer object to contain MSDN help pages
Dim objIEHelp


Sub ButtonState( blnCodeButtonsEnabled )
	CodeLabel.InnerHTML = "Code:"
	Code.title          = "After pressing the 'Generate Code' button, the generated code to display the available properties and their values for the selected WMI class and scripting language will be shown here"
	If blnCodeButtonsEnabled Then
		CopyCodeButton.Disabled     = True
		CopyCodeButton.Title        = ""
		ClearCodeButton.Disabled    = True
		ClearCodeButton.Title       = ""
		RunCodeButton.Disabled      = True
		RunCodeButton.Title         = ""
		GenerateCodeButton.Disabled = False
		GenerateCodeButton.Title    = "Press this button to generate the code that will display the properties and their values for the selected WMI class, in the selected scripting language"
	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"
		RunCodeButton.Disabled      = False
		RunCodeButton.Title         = "Press this button to run the generated (VBScript) code"
		GenerateCodeButton.Disabled = True
		GenerateCodeButton.Title    = ""
	End If
End Sub

Sub CheckUpdate( )
	' Change mouse pointer to hourglass while checking for update
	Document.Body.Style.Cursor = "wait"

	strLatestVer  = TextFromHTML( "http://www.robvanderwoude.com/updates/wmigen.txt" )
	lenLatestVer  = Len( strLatestVer )
	If lenLatestVer = 4 Then
		strCurrentVer = WMIGen.Version
		If strLatestVer < strCurrentVer Then
			Update.InnerHTML = "<p class=""White"">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=""http://www.robvanderwoude.com/wmigen.php"" class=""Red"">here</a>.</p>"
		End If
		If strLatestVer > strCurrentVer Then
			Update.InnerHTML = "<p class=""White"">You are using version " & strCurrentVer _
			                 & " of the WMI Code Generator.<br>An update to version " _
			                 & strLatestVer & " is available " _
			                 & "<a href=""http://www.robvanderwoude.com/wmigen.php"" class=""Red"">here</a>.</p>"
		End If
	End If

	' Change mouse pointer back to default
	Document.Body.Style.Cursor = "default"
End Sub


Sub CheckWindowSize( )
	myWidth = Document.Body.ClientWidth
	myHeight = Document.Body.ClientHeight
	largeBoxWidth  = CInt( myWidth / 9 )
	smallBoxWidth  = CInt( ( largeBoxWidth - 5 ) / 2 )
	smallBoxHeight = CInt( myHeight / 100 )
	codeBoxRows    = CInt( myHeight /  50 )
	If smallBoxHeight <  6 Then smallBoxHeight =  6
	If codeBoxRows    < 15 Then codeBoxRows    = 15

	Code.Cols       = largeBoxWidth
	Code.Rows       = codeBoxRows
	Properties.size = smallBoxHeight
	Methods.size    = smallBoxHeight
	WMIClasses.size = smallBoxHeight
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
	' http://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
		' List only Win32_* classes if /WIN32 was used
		If Left( UCase( objClass.Path_.Class ), 6 ) = "WIN32_" Or blnShowAllClasses Then
			' Skip Win32_Perf* classes if /NOPERF was used
			If Left( UCase( objClass.Path_.Class ), 10 ) <> "WIN32_PERF" Or blnShowPerfClasses Then
				' Skip WMI systemm properties starting with a double underscore
				If Left( objClass.Path_.Class, 2 ) <> "__" Then
					ReDim Preserve arrOptions( intSize )
					arrOptions( intSize ) = objClass.Path_.Class
					intSize = intSize + 1
				End If
			End If
		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
	' http://www.seroundtable.com/archives/015944.html
	strURLHelp = "http://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 HandleLanguageChange( )
	ButtonState True
	Code.Value = ""
End Sub


Sub RunCode( )
	Dim colItems, objItem, objOption, objProperty, objWMIService
	Dim strClass, strCode, strProperty

	' Change mouse pointer to hourglass while running the code
	Document.Body.Style.Cursor = "wait"
	Code.Value                 = " . . . Please Wait . . ."
	CodeLabel.InnerHTML        = "Result:"

	For Each objOption In WMIClasses.Options
		If objOption.Selected = True Then
			strClass = objOption.Text
		End If
	Next

	Set objWMIService = GetObject( "winmgmts://" & strComputer )
	Set colItems = objWMIService.InstancesOf( strClass )

	On Error Resume Next

	For Each objItem In colItems
		For Each objProperty In objItem.Properties_
			strProperty = objProperty.Name
			strCode = strCode & CreateLine( strProperty ) & " "
			If IsArray( objItem.Properties_.Item( strProperty, 0 ) ) Then
				strCode = strCode & Join( objItem.Properties_.Item( strProperty, 0 ), ";" )
			Else
				strCode = strCode & objItem.Properties_.Item( strProperty, 0 )
			End If
			strCode = strCode & vbCrLf
		Next
		strCode = strCode & vbCrLf
	Next

	On Error Goto 0

	Code.Value                  = strCode
	Code.title                  = "After pressing the 'Generate Code' button again, the generated code to display the available properties and their values for the selected WMI class and scripting language will be shown here once more"
	CopyCodeButton.Title        = "Press this button to copy the result to the clipboard"
	ClearCodeButton.Title       = "Press this button to erase the result"
	RunCodeButton.Disabled      = True
	RunCodeButton.Title         = ""
	GenerateCodeButton.Disabled = False
	GenerateCodeButton.Title    = "Press this button to generate the code that will display the properties and their values for the selected WMI class, in the selected scripting language"
	' Change mouse pointer back to default
	Document.Body.Style.Cursor  = "default"
End Sub


Sub ShowCode( )
	' Change mouse pointer to hourglass while running the code
	Document.Body.Style.Cursor = "wait"

	For Each objOption In WMIClasses.Options
		If objOption.Selected = True Then
			strClass = objOption.Text
		End If
	Next

	Select Case CodeLanguage.Value
		Case "Batch"
			ShowBatchCode strClass
		Case "CSharp"
			ShowCSharpCode strClass
		Case "JScript"
			ShowJScriptCode strClass
		Case "KiXtart"
			ShowKiXtartCode strClass
		Case "ObjectRexx"
			ShowObjectRexxCode strClass
		Case "Perl"
			ShowPerlCode strClass
		Case "PowerShell"
			ShowPowerShellCode strClass
		Case "Python"
			ShowPythonCode strClass
		Case "Ruby"
			ShowRubyCode strClass
		Case "VBDotNET"
			ShowVBDotNETCode strClass
		Case "VBScript"
			ShowVBScriptCode strClass
	End Select

	' Change mouse pointer back to default
	Document.Body.Style.Cursor  = "default"
	Code.title = "After pressing the 'Run WMI Code' button, the generated (VBScript) code will be executed, and the result will be shown here"
End Sub


Sub ShowBatchCode( myClass )
	strCode = "@ECHO OFF" _
	        & vbCrLf _
	        & ":: WMI query to list all properties and values of the " & myClass & " class" _
	        & vbCrLf _
	        & ":: This batch file was generated using the WMI Code Generator, Version " & WMIGen.Version _
	        & vbCrLf _
	        & ":: http://www.robvanderwoude.com/wmigen.php" _
	        & 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 " & myClass & " Get /Format:LIST" _
	        & vbCrLf

	Code.Value = strCode
	ButtonState False
End Sub


Sub ShowCSharpCode( myClass )
	Const wbemCIMTypeSint16    =   2 'Signed 16-bit integer
	Const wbemCIMTypeSint32    =   3 'Signed 32-bit integer
	Const wbemCIMTypeReal32    =   4 '32-bit real number
	Const wbemCIMTypeReal64    =   5 '64-bit real number
	Const wbemCIMTypeString    =   8 'String
	Const wbemCIMTypeBoolean   =  11 'Boolean value
	Const wbemCIMTypeObject    =  13 'CIM object
	Const wbemCIMTypeSint8     =  16 'Signed 8-bit integer
	Const wbemCIMTypeUint8     =  17 'Unsigned 8-bit integer
	Const wbemCIMTypeUint16    =  18 'Unsigned 16-bit integer
	Const wbemCIMTypeUint32    =  19 'Unsigned 32-bit integer
	Const wbemCIMTypeSint64    =  20 'Signed 64-bit integer
	Const wbemCIMTypeUint64    =  21 'Unsigned 64-bit integer
	Const wbemCIMTypeDatetime  = 101 'Date/time value
	Const wbemCIMTypeReference = 102 'Reference to a CIM object
	Const wbemCIMTypeChar16    = 103 '16-bit character

	Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" )
	Set objClass = objWMIService.Get( myClass )

	strCode = "// WMI query to list all properties and values of the " & myClass & " class" _
	        & vbCrLf _
	        & "// This C# code was generated using the WMI Code Generator, Version " & WMIGen.Version _
	        & vbCrLf _
	        & "// http://www.robvanderwoude.com/wmigen.php" _
	        & vbCrLf & vbCrLf _
	        & "using System;" _
	        & vbCrLf _
	        & "using System.Management;" _
	        & vbCrLf _
	        & "using System.Linq;" _
	        & vbCrLf & vbCrLf _
	        & "namespace " & myClass & "_Query" _
	        & vbCrLf _
	        & "{" _
	        & vbCrLf _
	        & vbTab & "public class WMIQuery" _
	        & vbCrLf _
	        & vbTab & "{" _
	        & vbCrLf _
	        & vbTab & vbTab & "public static void Main()" _
	        & vbCrLf _
	        & vbTab & vbTab & "{" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & "try" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & "{" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "ManagementObjectSearcher searcher = new ManagementObjectSearcher(""root\\CIMV2"", ""SELECT * FROM " & myClass & """);" _
	        & vbCrLf & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "foreach (ManagementObject queryObj in searcher.Get())" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "{" _
	        & vbCrLf
	        

	For Each objProperty In objClass.Properties_
		strCode = strCode & vbTab & vbTab & vbTab & vbTab & vbTab
		If objProperty.IsArray = True Then
			intCIMType = objProperty.CIMType
			strCIMType = "string"
			If intCIMType < 8 Then strCIMType = "UInt16"
			If intCIMType > 15 And intCIMType < 100 Then strCIMType = "UInt16"
			strCode = strCode & "if (queryObj[""" & objProperty.Name & """] == null)" _
			        & vbCrLf _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & "{" _
			        & vbCrLf _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "Console.WriteLine(""" & CreateLine( objProperty.Name ) & " {0}"", queryObj[""" & objProperty.Name & """]);" _
			        & vbCrLf _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & "}" _
			        & vbCrLf _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & "else" _
			        & vbCrLf _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & "{" _
			        & vbCrLf _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & strCIMType & "[] arrProperty = (" & strCIMType & "[])(queryObj[""" & objProperty.Name & """]);" _
			        & vbCrLf _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "Console.Write(""" & CreateLine( objProperty.Name ) & " "");" _
			        & vbCrLf _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "Console.WriteLine(string.Join("";"", arrProperty.Select(cap => cap.ToString()).ToArray()));" _
			        & vbCrLf _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & "}" _
			        & vbCrLf
		Else
			strCode = strCode & "Console.WriteLine(""" & CreateLine( objProperty.Name ) & " {0}"", queryObj[""" & objProperty.Name & """]);" & vbCrLf
		End If
	Next
	strCode = strCode & vbTab & vbTab & vbTab & vbTab & vbTab & "Console.WriteLine();" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "}" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & "}" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & "catch (ManagementException e)" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & "{" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "Console.OpenStandardError();" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "Console.WriteLine(""An error occurred while querying WMI: "" + e.Message);" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "Console.OpenStandardOutput();" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & "}" _
	        & vbCrLf _
	        & vbTab & vbTab & "}" _
	        & vbCrLf _
	        & vbTab & "}" _
	        & vbCrLf _
	        & "}" _
	        & vbCrLf

	Code.Value = strCode
	ButtonState False
End Sub


Sub ShowJScriptCode( myClass )
	' IsArray and Join() functionality "borrowed" from Scriptomatic 2.0
	' http://www.microsoft.com/downloads/details.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&DisplayLang=en
	Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" )
	Set objClass = objWMIService.Get( myClass )

	strCode = "// WMI query to list all properties and values of the " & myClass & " class" _
	        & vbCrLf _
	        & "// This JScript code was generated using the WMI Code Generator, Version " & WMIGen.Version _
	        & vbCrLf _
	        & "// http://www.robvanderwoude.com/wmigen.php" _
	        & 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 " & myClass & """, ""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"" ); }" _
			        & vbCrLf
		Else
			strCode = strCode & vbTab & "WScript.Echo( """ & CreateLine( objProperty.Name ) & " "" + objItem." & objProperty.Name & " );" _
			        & vbCrLf
		End If
	Next

	strCode = strCode _
	        & vbTab & "WScript.Echo( """" );" _
	        & vbCrLf & "}" _
	        & vbCrLf

	Code.Value = strCode
	ButtonState False
End Sub


Sub ShowKiXtartCode( myClass )
	Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" )
	Set objClass = objWMIService.Get( myClass )

	strCode = "; WMI query to list all properties and values of the " & myClass & " class" _
	        & vbCrLf _
	        & "; This KiXtart script was generated using the WMI Code Generator, Version " & WMIGen.Version _
	        & vbCrLf _
	        & "; http://www.robvanderwoude.com/wmigen.php" _
	        & 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 " & myClass & """, ""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( "
		strCode = strCode & "$objItem." & objProperty.Name
		If objProperty.IsArray = True Then strCode = strCode & ", "","" )"
		strCode = strCode & vbCrLf
	Next

	strCode = strCode _
	        & vbTab & "?" _
	        & vbCrLf _
	        & "Next" _
	        & vbCrLf & vbCrLf _
	        & "Quit" _
	        & vbCrLf

	Code.Value = strCode
	ButtonState False
End Sub


Sub ShowObjectRexxCode( myClass )
	' Based on the Rexx script samples found at the Script Repository:
	' http://www.microsoft.com/technet/scriptcenter/scripts/rexx/default.mspx?mfr=true
	' Tested with Open Object Rexx: http://www.oorexx.org/
	Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" )
	Set objClass = objWMIService.Get( myClass )

	strCode = "/*" _
	        & vbCrLf _
	        & "WMI query to list all properties and values of the " & myClass & " class" _
	        & vbCrLf _
	        & "This Open Object Rexx script was generated using the WMI Code Generator, Version " & WMIGen.Version _
	        & vbCrLf _
	        & "http://www.robvanderwoude.com/wmigen.php" _
	        & 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 " & myClass & """ )" _
	        & vbCrLf

	For Each objProperty In objClass.Properties_
		strCode = strCode & vbTab & "Say """ & CreateLine( objProperty.Name ) & " ""||"
		If objProperty.IsArray = True Then strCode = strCode & "Translate( "
		strCode = strCode & "objItem~" & objProperty.Name
		If objProperty.IsArray = True Then strCode = strCode & ", "","", ""0D0A""x )"
		strCode = strCode & vbCrLf
	Next

	strCode = strCode _
	        & vbTab & "Say" _
	        & vbCrLf _
	        & "End" _
	        & vbCrLf

	Code.Value = strCode
	ButtonState False
End Sub


Sub ShowPerlCode( myClass )
	Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" )
	Set objClass = objWMIService.Get( myClass )

	strCode = "#! perl" _
	        & vbCrLf & vbCrLf _
	        & "# WMI query to list all properties and values of the " & myClass & " class" _
	        & vbCrLf _
	        & "# This Perl script was generated using the WMI Code Generator, Version " & WMIGen.Version _
	        & vbCrLf _
	        & "# http://www.robvanderwoude.com/wmigen.php" _
	        & 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 " & myClass & """, ""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 "
		strCode = strCode & "$objItem->{ " & objProperty.Name & " }"
		If objProperty.IsArray = True Then strCode = strCode & " ) )"
		strCode = strCode & " . ""\n"";" & vbCrLf
	Next

	strCode = strCode _
	        & vbTab & "print ""\n"";" _
	        & vbCrLf _
	        & "}" _
	        & vbCrLf

	Code.Value = strCode
	ButtonState False
End Sub


Sub ShowPowerShellCode( myClass )
	Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" )
	Set objClass = objWMIService.Get( myClass )

	strCode = "# WMI query to list all properties and values of the " & myClass & " class" _
	        & vbCrLf _
	        & "# This PowerShell script was generated using the WMI Code Generator, Version " & WMIGen.Version _
	        & vbCrLf _
	        & "# http://www.robvanderwoude.com/wmigen.php" _
	        & vbCrLf & vbCrLf _
	        & "param( [string]$strComputer = ""."" )" _
	        & vbCrLf & vbCrLf _
	        & "$colItems = get-wmiobject -class """ & myClass & """ -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( myClass )
	' Python code based on Scriptomatic 2.0 generated code
	' http://www.microsoft.com/technet/scriptcenter/tools/scripto2.mspx
	Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" )
	Set objClass = objWMIService.Get( myClass )

	strCode = "#! python" _
	        & vbCrLf & vbCrLf _
	        & "# WMI query to list all properties and values of the " & myClass & " class" _
	        & vbCrLf _
	        & "# This Python script was generated using the WMI Code Generator, Version " & WMIGen.Version _
	        & vbCrLf _
	        & "# http://www.robvanderwoude.com/wmigen.php" _
	        & 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 " & myClass & """ )" _
	        & 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 ShowRubyCode( myClass )
	Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" )
	Set objClass = objWMIService.Get( myClass )

	strCode = "# WMI query to list all properties and values of the " & myClass & " class" _
	        & vbCrLf _
	        & "# This Ruby script was generated using the WMI Code Generator, Version " & WMIGen.Version _
	        & vbCrLf _
	        & "# http://www.robvanderwoude.com/wmigen.php" _
	        & vbCrLf & vbCrLf _
	        & "require 'win32ole'" _
	        & vbCrLf & vbCrLf _
	        & "objWMIService = WIN32OLE.connect( ""winmgmts://."" )" _
	        & vbCrLf _
	        & "colItems = objWMIService.ExecQuery( ""SELECT * FROM " & myClass & """ )" _
	        & vbCrLf & vbCrLf _
	        & "for objItem in colItems do" _
	        & vbCrLf

	For Each objProperty In objClass.Properties_
		strCode = strCode & vbTab & "puts """ & CreateLine( objProperty.Name ) & " #{objItem." & objProperty.Name & "}""" & vbCrLf
	Next

	strCode = strCode _
	        & vbTab & "puts" _
	        & vbCrLf _
	        & "end" _
	        & vbCrLf

	Code.Value = strCode
	ButtonState False
End Sub


Sub ShowVBDotNETCode( myClass )
	Const wbemCIMTypeSint16    =   2 'Signed 16-bit integer
	Const wbemCIMTypeSint32    =   3 'Signed 32-bit integer
	Const wbemCIMTypeReal32    =   4 '32-bit real number
	Const wbemCIMTypeReal64    =   5 '64-bit real number
	Const wbemCIMTypeString    =   8 'String
	Const wbemCIMTypeBoolean   =  11 'Boolean value
	Const wbemCIMTypeObject    =  13 'CIM object
	Const wbemCIMTypeSint8     =  16 'Signed 8-bit integer
	Const wbemCIMTypeUint8     =  17 'Unsigned 8-bit integer
	Const wbemCIMTypeUint16    =  18 'Unsigned 16-bit integer
	Const wbemCIMTypeUint32    =  19 'Unsigned 32-bit integer
	Const wbemCIMTypeSint64    =  20 'Signed 64-bit integer
	Const wbemCIMTypeUint64    =  21 'Unsigned 64-bit integer
	Const wbemCIMTypeDatetime  = 101 'Date/time value
	Const wbemCIMTypeReference = 102 'Reference to a CIM object
	Const wbemCIMTypeChar16    = 103 '16-bit character

	Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" )
	Set objClass = objWMIService.Get( myClass )

	strCode = "' WMI query to list all properties and values of the " & myClass & " class" _
	        & vbCrLf _
	        & "' This VB .NET code was generated using the WMI Code Generator, Version " & WMIGen.Version _
	        & vbCrLf _
	        & "' http://www.robvanderwoude.com/wmigen.php" _
	        & vbCrLf & vbCrLf _
	        & "Imports System" _
	        & vbCrLf _
	        & "Imports System.Management" _
	        & vbCrLf & vbCrLf _
	        & "Namespace WMIGen___" & myClass _
	        & vbCrLf _
	        & vbTab & "Public Class WMIGenQuery" _
	        & vbCrLf _
	        & vbTab & vbTab & "Public Overloads Shared Function Main() As Integer" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & "Try" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "Dim searcher As New ManagementObjectSearcher(""root\CIMV2"", ""SELECT * FROM " & myClass & """)" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "Dim arrPropertyInt() As UInt16" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "Dim arrPropertyStr() As String" _
	        & vbCrLf & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "For Each queryObj As ManagementObject In searcher.Get()" _
	        & vbCrLf

	        

	For Each objProperty In objClass.Properties_
		strCode = strCode & vbTab & vbTab & vbTab & vbTab & vbTab
		If objProperty.IsArray = True Then
			intCIMType = objProperty.CIMType
			strCIMType = "String"
			strArrayPr = "arrPropertyStr"
			If intCIMType < 8 Then strCIMType = "UInt16"
			If intCIMType > 15 And intCIMType < 100 Then strCIMType = "UInt16"
			If strCIMType = "UInt16" Then strArrayPr = "arrPropertyInt"
			strCode = strCode _
			        & "If queryObj(""" & objProperty.Name & """) Is Nothing Then" _
			        & vbCrLf _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "Console.WriteLine(""" & CreateLine( objProperty.Name ) & " {0}"", queryObj(""" & objProperty.Name & """))" _
			        & vbCrLf _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & "Else" _
			        & vbCrLf _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & strArrayPr & " = queryObj(""" & objProperty.Name & """)" _
			        & vbCrLf
			If strCIMType = "UInt16" Then
				strCode = strCode _
				        & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "ReDim arrPropertyStr(UBound(arrPropertyInt))" _
				        & vbCrLf _
                        & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "For i = 0 To UBound(arrPropertyInt)" _
                        & vbCrLf _
                        & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "arrPropertyStr(i) = CStr(arrPropertyInt(i))" _
                        & vbCrLf _
                        & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "Next" _
                        & vbCrLf
			End If
			strCode = strCode _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "Console.WriteLine(""" & CreateLine( objProperty.Name ) & " {0}"", Join(arrPropertyStr, "";""))" _
			        & vbCrLf _
			        & vbTab & vbTab & vbTab & vbTab & vbTab & "End If" _
			        & vbCrLf
		Else
			strCode = strCode & "Console.WriteLine(""" & CreateLine( objProperty.Name ) & " {0}"", queryObj(""" & objProperty.Name & """))" & vbCrLf
		End If
	Next
	strCode = strCode _
	        & vbTab & vbTab & vbTab & vbTab & "Next" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & "Catch err As ManagementException" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "Console.OpenStandardError()" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "Console.WriteLine(""An error occurred while querying WMI: "" & err.Message)" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & vbTab & "Console.OpenStandardOutput()" _
	        & vbCrLf _
	        & vbTab & vbTab & vbTab & "End Try" _
	        & vbCrLf _
	        & vbTab & vbTab & "End Function" _
	        & vbCrLf _
	        & vbTab & "End Class" _
	        & vbCrLf _
	        & "End Namespace" _
	        & vbCrLf

	Code.Value = strCode
	ButtonState False
End Sub


Sub ShowVBScriptCode( myClass )
	' IsArray an Join() functionality "borrowed" from Scriptomatic 2.0
	' http://www.microsoft.com/downloads/details.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&DisplayLang=en
	Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}root/cimv2" )
	Set objClass = objWMIService.Get( myClass )

	strCode = "' WMI query to list all properties and values of the " & myClass & " class" _
	        & vbCrLf _
	        & "' This VBScript code was generated using the WMI Code Generator, Version " & WMIGen.Version _
	        & vbCrLf _
	        & "' http://www.robvanderwoude.com/wmigen.php" _
	        & 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 " & myClass & """, ""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( "
		strCode = strCode & "objInstance." & objProperty.Name
		If objProperty.IsArray = True Then strCode = strCode & ", "","" )"
		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 http://dev.remotenetworktechnology.com/wsh/rubegoldberg.htm
	' Improved wait-until-ready routine for HTAs by McKirahan on
	' http://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
	document.title = "WMI Code generator " & WMIGen.Version
	ButtonState True
	If InStr( UCase( WMIGen.CommandLine ), "/NOPERF" ) Then blnShowPerfClasses = False
	If InStr( UCase( WMIGen.CommandLine ), "/WIN32" )  Then blnShowAllClasses  = False
	FillClassDropDown
	CheckWindowSize( )
	CheckUpdate( )
	CreateIEHelp( )
	objIEHelp.Visible = 0
End Sub


Sub Window_Onunload
	On Error Resume Next
	objIEHelp.Quit
	Set objIEHelp = Nothing
	On Error Goto 0
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">&nbsp;</span>

<table border="0" cellspacing="10">
<tr align="Center">
    <th colspan="2" title="Select a WMI class from this drop-down list, then select a scripting language and press the 'Generate Code' button to show the code for the selected WMI query and the selected scripting language 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, then select a scripting language and press the 'Generate Code' button to show the code for the selected WMI query and the selected scripting language 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 id="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 id="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 id="CodeLabel" title="After pressing the 'Generate 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" class="Button" 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 id="Code" rows="20" cols="70" readonly></textarea></td>
</tr>
<tr align="Left">
    <th colspan="2" title="Select a scripting language from this drop-down list and press the 'Generate Code' button to show the code for the selected WMI query and scripting language in the text area above" align="Left">Select a scripting language:
        <select name="CodeLanguage" id="CodeLanguage" onchange="HandleLanguageChange()" style="text-align: left; margin-left: 0">
            <option value="Batch">Batch</option>
            <option value="CSharp">C#</option>
            <option value="JScript">JScript</option>
            <option value="KiXtart">KiXtart</option>
            <option value="ObjectRexx">ObjectRexx</option>
            <option value="Perl">Perl</option>
            <option value="PowerShell">PowerShell</option>
            <option value="Python">Python</option>
            <option value="Ruby">Ruby</option>
            <option value="VBDotNET">VB .NET</option>
            <option value="VBScript">VBScript</option>
        </select></th>
</tr>
<tr align="Center">
    <td colspan="2">
        <input id="GenerateCodeButton" onclick="ShowCode"  type="submit" value="Generate Code"     class="Button" title="Press this button to generate the code that will display the properties and their values for the selected WMI class, in the selected script language">
        <input id="RunCodeButton"      onclick="RunCode"   type="submit" value="Run WMI Code"      class="Button" title="Press this button to run the generated (VBSCript) code">
        <input id="ClearCodeButton"    onclick="ClearCode" type="submit" value="Clear"             class="Button" title="Press this button to erase the generated code">
        <input id="CopyCodeButton"     onclick="CopyCode"  type="submit" value="Copy to Clipboard" class="Button" title="Press this button to copy the generated code to the clipboard"></td>
</tr>
</table>

<p><span style="font-size: 12pt">WMI Code Generator,&nbsp; Version <span id="AppVersion">0.00</span></span><br>
&copy; 2006 - 2010, Rob van der Woude<br>
<a href="http://www.robvanderwoude.com/">http://www.robvanderwoude.com</a></p>

<p>Based on the Microsoft TechNet ScriptCenter article
<a href="http://www.microsoft.com/technet/scriptcenter/resources/guiguy/default.mspx">Scripting Eye for the GUI Guy</a>.<br>
Created with the help of WBEMTEST, the Scripting Guys'
<a href="http://www.microsoft.com/technet/scriptcenter/tools/scripto2.mspx">Scriptomatic</a> and
<a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=231D8143-F21B-4707-B583-AE7B9152E6D9&displaylang=en">HTA Helpomatic</a>
tools, and Adersoft's <a href="http://www.htaedit.com/">HTAEdit</a>.<br>
Help search function based on
<a href="http://www.google.com/">Google Search</a> and completed with help from
<a href="http://www.seroundtable.com/archives/015944.html">Search Engine Roundtable</a>.</p>

</div>

</body>
</html>    


Como obtener el código con el Generador de Códigos de WMI

Para obtener el código del Generador, para crear tu propia aplicación, sigue los siguientes pasos:
1- Inicia la aplicación y espera a que termine de cargar.
2- En el menú de la ventana superior selecciona una clase de WMI, por ejemplo una perteneciente a Win32.
3- En el cuadro inferior selecciona una propiedad de las disponibles.
4- Selecciona el formato del código de los disponibles. El predeterminado es batch, pero se puede escoger entre C+, JScript, VBScript, Perl y otros.
5- Presiona el botón "Generate Code".
En la siguiente imagen se puede ver cómo obtener el código, para crear un archivo batch que muestra toda la información que proporciona WMI sobre el disco duro de la computadora (Win32_LogicalDisk).
Generador de Códigos de WMI


Archivos batch de ejemplo

Crea un archivo batch de prueba usando el siguiente código, que muestra la información en la ventana del Símbolo del sistema.
@ECHO OFF
WMIC.EXE /Node:"%Node%" /Output:STDOUT Path Win32_LogicalDisk Get /Format:LIST
pause

Crea un archivo batch de prueba usando el siguiente código, que escribe la información anterior en un archivo de texto en el escritorio.
@ECHO OFF
WMIC.EXE /Node:"%Node%" /Output:%userprofile%\Desktop\lista.txt Path Win32_LogicalDisk Get /Format:LIST
PAUSE

Más información

Como usar los comandos de la consola de WMIC en Windows
Páginas y aplicaciones HTA, uso y funciones prácticas
Como crear una página o aplicación HTA
Aplicaciones HTA para obtener información y diagnosticar redes
Aplicación HTA para validar archivos XML offline


Comparte

Facebook
Twitter

Sígueme en las redes sociales

Norfipc en Facebook Norfipc en Twitter Canales RSS con las últimas publicaciones
Inicio | Mapa del sitio | Buscar | Sobre mí