jokke Posted September 24, 2009 Posted September 24, 2009 Hi!Im trying to write a com object where i want to fetch the key and value of the returned sql object.Heres an failed atempt:#include <array.au3> $a = _querywmi("Win32_UserAccount") _ArrayDisplay($a,"query") Func _querywmi($class = "Win32_UserAccount", $strComputer = "localhost") $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $specificObj = $objWMIService.ExecQuery("SELECT * FROM " & $class & "", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If isObj($specificObj) then For $obj In $specificObj If Not IsDeclared("r") Then Local $r[1][2] $r[0][0] = $obj.Key $r[0][0] = $obj.Value Else ReDim $r[UBound($r)+1][2] $r[UBound($r)-1][0] = $obj.Key $r[UBound($r)-1][1] = $obj.Value EndIf Next EndIf Return $r EndFuncAll feedback appreciated UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
DW1 Posted September 24, 2009 Posted September 24, 2009 What are you trying to do exactly? I would like to help, but I don't completely understand what you are trying to do with this script. AutoIt3 Online Help
DW1 Posted September 24, 2009 Posted September 24, 2009 (edited) If I am not mistaken, you were trying to do something like this? #include <array.au3> $a = _querywmi("Win32_UserAccount") _ArrayDisplay($a, "query") Func _querywmi($class = "Win32_UserAccount", $strComputer = "localhost") $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $specificObj = $objWMIService.ExecQuery("SELECT * FROM " & $class & "", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($specificObj) Then ConsoleWrite("test 1" & @CRLF) For $obj In $specificObj For $objProperty In $obj.Properties_() If Not IsDeclared("r") Then Local $r[1][2] $r[0][0] = $objProperty.Name $r[0][1] = $objProperty.Value Else ReDim $r[UBound($r) + 1][2] $r[UBound($r) - 1][0] = $objProperty.Name $r[UBound($r) - 1][1] = $objProperty.Value EndIf Next ReDim $r[UBound($r) + 1][2] $r[UBound($r) - 1][0] = '---------------' $r[UBound($r) - 1][1] = '---------------' Next EndIf Return $r EndFunc ;==>_querywmi Thanks to the Autoit Scriptomatic Tool source code for this: For $objProperty in $objClass.Properties_() ; Must use (), because method ends with an underscore EDIT: There are many queries that will fail with this due to WMI returning an array of data. For a workaround, check out the Autoit Scriptomatic Tool source code. Specifically this portion: For $objProperty In $objClass.Properties_() ; Must use (), because method ends with an underscore If $objProperty.IsArray = True Then $strScriptCode = $strScriptCode & " $str" & $objProperty.Name & " = $objItem." & $objProperty.Name & "(0)" & @CRLF $strScriptCode = $strScriptCode & " $Output = $Output & " & $strRowStart & $objProperty.Name & $strColumnSeparator & Chr(34) & " & $str" & $objProperty.Name & $strRowEnd & @CRLF ElseIf $objProperty.CIMTYPE = 101 Then $bHasDates = True $strScriptCode = $strScriptCode & " $Output = $Output & " & $strRowStart & $objProperty.Name & $strColumnSeparator & Chr(34) & " & WMIDateStringToDate($objItem." & $objProperty.Name & ")" & $strRowEnd & @CRLF Else $strScriptCode = $strScriptCode & " $Output = $Output & " & $strRowStart & $objProperty.Name & $strColumnSeparator & Chr(34) & " & $objItem." & $objProperty.Name & $strRowEnd & @CRLF EndIf Next Edited September 24, 2009 by danwilli AutoIt3 Online Help
DW1 Posted September 24, 2009 Posted September 24, 2009 -Added support for when the property returns an array as shown in the AutoIt Scriptomatic Tool source code. -Added the WMIDateStringToDate() function from AutoIt Scriptomatic Tool source code. expandcollapse popup#include <array.au3> $a = _querywmi("Win32_BIOS") _ArrayDisplay($a, "query") Func _querywmi($class = "Win32_UserAccount", $strComputer = "localhost") $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $specificObj = $objWMIService.ExecQuery("SELECT * FROM " & $class & "", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($specificObj) Then ConsoleWrite("test 1" & @CRLF) For $obj In $specificObj For $objProperty In $obj.Properties_() If Not IsDeclared("r") Then Local $r[1][2] Else ReDim $r[UBound($r) + 1][2] EndIf $r[UBound($r) - 1][0] = $objProperty.Name If $objProperty.IsArray = True Then $r[UBound($r) - 1][1] = $objProperty.Value(0) ElseIf $objProperty.CIMTYPE = 101 Then $r[UBound($r) - 1][1] = WMIDateStringToDate($objProperty.Value) Else $r[UBound($r) - 1][1] = $objProperty.Value EndIf Next ReDim $r[UBound($r) + 1][2] $r[UBound($r) - 1][0] = '---------------' $r[UBound($r) - 1][1] = '---------------' Next EndIf Return $r EndFunc ;==>_querywmi Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc AutoIt3 Online Help
jokke Posted September 25, 2009 Author Posted September 25, 2009 Perfect thanks!! UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
jokke Posted September 25, 2009 Author Posted September 25, 2009 (edited) This was actually my goal of this, making the wmi call more like how a regular SQL select is done. expandcollapse popup#include <array.au3> $a = _querywmi("SELECT * FROM Win32_OperatingSystem") _ArrayDisplay($a, "query") Func _querywmi($query, $strComputer = "localhost") $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $specificObj = $objWMIService.ExecQuery($query, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($specificObj) Then For $obj In $specificObj For $objProperty In $obj.Properties_() If Not IsDeclared("r") Then Local $r[1][2] Else ReDim $r[UBound($r) + 1][2] EndIf $r[UBound($r) - 1][0] = $objProperty.Name If $objProperty.IsArray = True Then $t = $objProperty.Value $r[UBound($r) - 1][1] = _ArrayToString($t,@TAB) ElseIf $objProperty.CIMTYPE = 101 Then $r[UBound($r) - 1][1] = WMIDateStringToDate($objProperty.Value) Else $r[UBound($r) - 1][1] = $objProperty.Value EndIf Next Next EndIf If IsDeclared("r") Then Return $r Else Return False EndIf EndFunc ;==>_querywmi Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc Edited September 25, 2009 by jokke UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now