Jump to content

Recommended Posts

Posted

I'm trying to do this, but can't figure the proper format:

$result = $result & $obj.$property

Here is the full script:

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$thisComputerName = GetSpecificWMI("Name","Win32_ComputerSystem")

MsgBox(4096, "Computer name", $thisComputerName)

Func GetSpecificWMI($property, $class)
    $result = ""
    $specificObj = $objWMIService.ExecQuery("SELECT " & $property & " FROM " & $class & "", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If isObj($specificObj) then
        For $obj In $specificObj
            $result = $result & $obj.$property
        Next
    EndIf
    Return $result
EndFunc
Posted

For example, in this instance $property = "Name"

Change the line inquestion to

$result = $result & $obj.Name

and it works, but

$result = $result & $obj.$property

doesn't.

Posted (edited)

Hello.

I've found an solution for your problem. Check this out:

Func GetSpecificWMI($property, $class)
    $result = ""
    $specificObj = $objWMIService.ExecQuery("SELECT * FROM " & $class & "", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If isObj($specificObj) then
        For $obj In $specificObj
            $result = $result & Execute("$obj." & Eval("property"))
        Next
    EndIf
    Return $result
EndFunc

EDIT: Enjoy this piece of code from Russia :)

Edited by Crystall

Hello World!

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
×
×
  • Create New...