Jump to content

using $var1.$var in expression


Recommended Posts

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
Link to comment
Share on other sites

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!

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...