Jump to content
Sign in to follow this  

WMI - get single value

Recommended Posts



For a management tool I need to query several different values from WMI. Point is, I have to do that from Linux. Yes, I know, this is AutoIT, and it's for Windows. But you guys have proven to be a most often very helpful and professional community, so I thought, let's just ask...you.

On Windows, if I query WMI from VB or AutoIt, I usually do something like this:

Local $wbemFlagReturnImmediately= 0x10
Local $wbemFlagForwardOnly      = 0x20
Local $h_wbemFlags              = $wbemFlagReturnImmediately + $wbemFlagForwardOnly
$s_ComputerName                 = "localhost"
$o_WMIService                   = ObjGet("winmgmts:\\" & $s_ComputerName & "\root\CIMV2")
$o_LogicalDiskC                 = $o_WMIService.ExecQuery("SELECT Size FROM Win32_LogicalDisk WHERE Description = 'Local Fixed Disk' AND Name = 'C:'", "WQL", $h_wbemFlags)

If IsObj ($o_LogicalDiskC) Then
    For $o_item in $o_LogicalDiskC
        ConsoleWrite(@CRLF & $o_item.Size & " Bytes - " & Round($o_item.Size /1024 /1024 /1024, 2) & " GBytes" & @CRLF)
    ConsoleWrite(@CRLF & "No Object" & @CRLF)
Okay. But now I only need the value of .Size and not the collection of (in this case one) object(s) that is returned by the query. So my question: Is there a way to phrase a WMI query in WQL that only returns this value as an int or string or something?



Edited by cherdeg

Share this post

Link to post
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

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.