Jump to content

[Solved] WMI Query Question


Recommended Posts

Good evening everyone :)
I'm working on a little project of mines, and I was trying to use WMI Object.
The question which I don't find an answer is: 

Once I do the query with WMI Object, something like "SELECT * FROM Win32_LogonSession", instead of specify the field of the collection returned, ( i.e. $colItems.Caption ), can I loop though each property and each value of the property, writing so one row of code only?
Hope my question was clear enough.
Thanks in advance.

Best Regards.

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

@Earthshine
Thanks a lot, Sir!
Since my knowledge of WMI is very basic, I didn't know about that, AND, I was "Googling" around, before creating this thread, and I found this:
https://social.technet.microsoft.com/Forums/systemcenter/en-US/2a0078db-2053-4e21-9262-62ffbc156862/enumerating-fields-returned-with-a-wmi-query?forum=configmgrgeneral

But, as it seems, that's not the same thing applicable in AutoIt.
By the way, thanks a lot :)

Best Regards. 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

i googled the following string:

enumerate wmi object properties autoit

it helps to ask the question clearly i have found with google to get more effective answers quickly. it's like my signature... LOL, I've been at this a long time as well. Happy programming. :)

 

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

@Earthshine
Your signature seems like the phrase from "I Robot", when the Doctor says to Will Smith: "That detective, is the right question" :D
By the way, I was trying to query Win32_PointingDevice, which works like a charm; but, I was interested to see how properties which are arrays, were displayed...
For example, there is the certainty that PowerManagementCapabilities[] will always be an array?
In that case, I tried with:

 

For $objWMI_Item In $objWMIQueryResult
    For $objWMIProperty In $objWMI_Item.Properties_
        If IsArray($objWMIProperty.Name) Then
            ConsoleWrite($objWMIProperty.Name & " is an array!" & @CRLF)
        Else
            ConsoleWrite($objWMIProperty.Name & " = " & $objWMIProperty.Value & @CRLF)
        EndIf
    Next
    ConsoleWrite("--------------------" & @CRLF)
Next

But I don't know if this could be correct.
Thanks again for your help :)

Best Regards.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

I generated this with ScriptoMatic, in the examples that get installed, for the pointing device.

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$sComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $sComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$oWMIService = ObjGet("winmgmts:\\" & $sComputer & "\root\CIMV2")
$colItems = $oWMIService.ExecQuery("SELECT * FROM Win32_PointingDevice", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
   For $objItem In $colItems
      $Output = $Output & "Availability: " & $objItem.Availability & @CRLF
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF
      $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF
      $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF
      $Output = $Output & "DeviceInterface: " & $objItem.DeviceInterface & @CRLF
      $Output = $Output & "DoubleSpeedThreshold: " & $objItem.DoubleSpeedThreshold & @CRLF
      $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF
      $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF
      $Output = $Output & "Handedness: " & $objItem.Handedness & @CRLF
      $Output = $Output & "HardwareType: " & $objItem.HardwareType & @CRLF
      $Output = $Output & "InfFileName: " & $objItem.InfFileName & @CRLF
      $Output = $Output & "InfSection: " & $objItem.InfSection & @CRLF
      $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
      $Output = $Output & "IsLocked: " & $objItem.IsLocked & @CRLF
      $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF
      $Output = $Output & "Manufacturer: " & $objItem.Manufacturer & @CRLF
      $Output = $Output & "Name: " & $objItem.Name & @CRLF
      $Output = $Output & "NumberOfButtons: " & $objItem.NumberOfButtons & @CRLF
      $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF
      $Output = $Output & "PointingType: " & $objItem.PointingType & @CRLF
      $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0)
      $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF
      $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF
      $Output = $Output & "QuadSpeedThreshold: " & $objItem.QuadSpeedThreshold & @CRLF
      $Output = $Output & "Resolution: " & $objItem.Resolution & @CRLF
      $Output = $Output & "SampleRate: " & $objItem.SampleRate & @CRLF
      $Output = $Output & "Status: " & $objItem.Status & @CRLF
      $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF
      $Output = $Output & "Synch: " & $objItem.Synch & @CRLF
      $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF
      $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF
      If MsgBox(1,"WMI Output",$Output) = 2 Then ExitLoop
      $Output=""
   Next
Else
   MsgBox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_PointingDevice" )
EndIf


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

 

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

remember you are querying a database of sorts, you get a result set to iterate through. I don't think those are array's the way you are thinking.

and my sig is from I, Robot, maybe a little different but supposed to convey the same message.

that was a great movie, but nowhere near what Issac Asimov created with that story. But, I loved it anyway.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Good morning @Earthshine:)
So, a normal

If IsArray($objProperty.Value) Then
    ; Do stuffs with array
Else
    ; Do stuffs if is not an array
EndIf

would be correct, isn't it? :)
Thanks for your help.

Best Regards.

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...