Sign in to follow this  
Followers 0
minimen456

WMI Query. How to get data from object?

4 posts in this topic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\ROOT\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT DeviceID,FreeSpace FROM Win32_LogicalDisk WHERE DeviceID = 'C:'", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

How can I get data(FreeSpace) from $colItems object? Can I do it without using loop?

Share this post


Link to post
Share on other sites



Did you try this... (click on it)

$val = DriveSpaceFree("c:\")

Here is a working code-piece:

Local $objWMI = ObjGet('winmgmts:root\cimv2')
Local $objClass = $objWMI.ExecQuery('SELECT * FROM Win32_LogicalDisk Where DeviceID="C:"')

Local $string = ''

For $objItem In $objClass
    $string &= 'DeviceID = ' & $objItem.DeviceID & @CRLF
    $string &= 'FreeSpace = ' & $objItem.FreeSpace & @CRLF
    ExitLoop
Next

MsgBox(0, '', $string)

There are ways to do it without a loop, but I wouldn't recommend it. Too many things can go wrong.


Make yourself sheep and the wolves will eat you - Benjamin Franklin

Share this post


Link to post
Share on other sites

Did you have a look at the tool in the Example Scripts section of the forum. It generates AutoIt code for you to query WMI.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Try this:

$objWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & '\root\cimv2:Win32_LogicalDisk="C:"')
MsgBox(0, "TEST", "Free Diskspace on C: " & $objWMI.FreeSpace & " bytes / " & Round($objWMI.FreeSpace / 1024^2) & " mb")

Br,

UEZ

2 people like this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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  
Followers 0