;===============================================================# ; WMI_Query.au3 ; Description.: Displays WMI Class Info ; Released....: April 06, 2012 by ripdad ; Version.....: 1.04 ; ; Modified....: April 08, 2012 ; * added: Cache, saved in @AppDataDir\WMI_Query_Cache ; * added: _DeleteCache(), Press F9 to delete. ; * added: WM_GETMINMAXINFO(), GUI minimal resize. ; ; Modified....: April 09, 2012 ; * fixed: HTML tags (left and right arrows) in some ; WMI strings, causing some data not to display. ; Modified....: April 11, 2012 ; * fixed: Method Names that have a void CIMType. ; Would cause method name not to display. ; ; Modified....: May 22, 2012 ; * fixed: Adjusted the height for the combo's. ; x64 restriction has been removed. ;===============================================================# ; #RequireAdmin #include 'array.au3' ; Opt('MustDeclareVars', 1) Opt('TrayAutoPause', 0) ; Local Const $s_Div = '
Loading Name Spaces...
') If @error Then MsgBox(8208, 'Error', 'IE OBJECT: Write Error - Exiting' & @TAB, 8) Exit EndIf $Suppress_ErrorMsg = 0 ; GUICtrlCreateGroup('Filter', 590, 4, 100, 91) Local $ID_radio1 = GUICtrlCreateRadio('Abstract', 600, 25, 75, 18) Local $ID_radio2 = GUICtrlCreateRadio('Dynamic', 600, 45, 75, 18) Local $ID_radio3 = GUICtrlCreateRadio('Show All', 600, 65, 75, 18) GUICtrlCreateGroup('Name Space', 10, 4, 570, 45) Local $ID_NameSpaces = GUICtrlCreateCombo('', 20, 20, 550, 400) GUICtrlCreateGroup('Class', 10, 50, 570, 45) Local $ID_ClassNames = GUICtrlCreateCombo('', 20, 66, 550, 400) GUICtrlSetState($ID_radio2, 1) GUISetState(@SW_SHOW, $ID_GUI) ; _WMI_Init() ; GUIRegisterMsg(0x0024, 'WM_GETMINMAXINFO') ; While 1 Switch GUIGetMsg() Case -3 ExitLoop Case $ID_radio1 $sType = 'Abstract' $iFilter = 1 _WMI_GUI_LoadClasses() Case $ID_radio2 $sType = 'Dynamic' $iFilter = 1 _WMI_GUI_LoadClasses() Case $ID_radio3 $sType = 'Show All' $iFilter = 0 _WMI_GUI_LoadClasses() Case $ID_NameSpaces _WMI_GUI_LoadClasses() Case $ID_ClassNames If Not StringRegExp(GUICtrlRead($ID_ClassNames), $sPattern) Then _GUI_Disable() _IE_Write_HTML('Loading...
') _WMI_Class_Description(GUICtrlRead($ID_ClassNames), GUICtrlRead($ID_NameSpaces)) _GUI_Enable() ControlFocus('WMI Query', '', '[CLASSNN:Internet Explorer_Server1]') EndIf EndSwitch WEnd Exit ; Func _Exit() $ObjIE = 0 GUIDelete($ID_GUI) Exit EndFunc ; Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam) $tagMaxinfo = DllStructCreate('int;int;int;int;int;int;int;int;int;int', $lParam) DllStructSetData($tagMaxinfo, 7, 700); minimum-width DllStructSetData($tagMaxinfo, 8, 600); minimum-height ;DllStructSetData($tagMaxinfo, 9, 1024); maximum-width ;DllStructSetData($tagMaxinfo, 10, 768); maximum-height Return 'GUI_RUNDEFMSG' EndFunc ; Func _GUI_Enable(); $GUI_ENABLE GUICtrlSetState($ID_ClassNames, 64) GUICtrlSetState($ID_NameSpaces, 64) EndFunc ; Func _GUI_Disable(); $GUI_DISABLE GUICtrlSetState($ID_ClassNames, 128) GUICtrlSetState($ID_NameSpaces, 128) EndFunc ; Func _IE_Write_HTML($strBody) Local $sHTML = '' & @CRLF $sHTML &= $strBody & @CRLF $sHTML &= '' ;================================ $ObjIE.Navigate('about:blank') $ObjIE.Document.Write($sHTML) $ObjIE.Document.Close() EndFunc ; Func _DeleteCache() If FileExists($sPath_Cache) Then If DirRemove($sPath_Cache, 1) Then MsgBox(8256, 'WMI Query', 'Cache Deleted') EndIf EndIf EndFunc ; Func _WMI_Init() If Not FileExists($sPath_Cache) Then DirCreate($sPath_Cache) EndIf Local $hFile, $sClasses, $sNameSpaces Local $NameSpacesCache = $sPath_Cache & '\Name-Spaces.dat' If FileExists($NameSpacesCache) Then $sNameSpaces = StringReplace(FileRead($NameSpacesCache), @CRLF, '|') Else _GUI_Disable() $sNameSpaces = _WMI_LoadNameSpaces() $hFile = FileOpen($NameSpacesCache, 2) If $hFile <> -1 Then FileWrite($hFile, StringReplace($sNameSpaces, '|', @CRLF)) FileClose($hFile) Else MsgBox(8240, 'WMI Query', 'Cannot Write to Cache') EndIf _GUI_Enable() EndIf GUICtrlSetData($ID_NameSpaces, $sNameSpaces, 'CIMV2') _WMI_GUI_LoadClasses() EndFunc ; Func _WMI_GUI_LoadClasses() If Not FileExists($sPath_Cache) Then DirCreate($sPath_Cache) EndIf GUICtrlSetData($ID_ClassNames, '') Local $hFile, $sClasses, $sNameSpace = GUICtrlRead($ID_NameSpaces) Local $ClassCache = $sPath_Cache & '\' & StringReplace($sNameSpace & '-' & $sType & '.dat', '\', '-') If FileExists($ClassCache) Then $sClasses = StringReplace(FileRead($ClassCache), @CRLF, '|') If $sClasses <> 'No Classes Found' Then GUICtrlSetData($ID_ClassNames, 'Select a Class|' & $sClasses, 'Select a Class') Else GUICtrlSetData($ID_ClassNames, $sClasses, $sClasses) EndIf Else _GUI_Disable() _IE_Write_HTML($s_Span & 'WMI Query v1.04Loading Classes: ' & $sType & '
') $sClasses = _WMI_LoadClasses($sNameSpace, $iFilter, $sType) If @error Then $sClasses = 'No Classes Found' GUICtrlSetData($ID_ClassNames, $sClasses, $sClasses) Else GUICtrlSetData($ID_ClassNames, 'Select a Class|' & $sClasses, 'Select a Class') EndIf $hFile = FileOpen($ClassCache, 2) If $hFile <> -1 Then FileWrite($hFile, StringReplace($sClasses, '|', @CRLF)) FileClose($hFile) Else MsgBox(8240, 'WMI Query', 'Cannot Write to Cache') EndIf _GUI_Enable() EndIf _IE_Write_HTML($s_Span & 'WMI Query v1.04Ready
') EndFunc ; Func _WMI_Class_Description($sClass, $sName_Space = 'CIMV2') Local $objWMI = ObjGet($sWMI_Moniker & $sName_Space) If @error Or Not IsObj($objWMI) Then Return SetError(-1) Local $objClass = $objWMI.Get($sClass, 0x20000); wbemFlagUseAmendedQualifiers If @error Or Not IsObj($objClass) Then Return SetError(-2) ; Local $Name, $Value, $Description = 0, $String = '' Local $s = $s_Span & $sClass & '