Jump to content
Sign in to follow this  
eternaluxe

using $var1.$var in expression

Recommended Posts

eternaluxe

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

Share this post


Link to post
Share on other sites
nguyenbason

What do you want to do? You are assigning value for $result that taking from WMI query?

You want to separate each value or what?

$result = $result & $obj.$property & "|"

UnderWorldVN- Just play the way you like it

Share this post


Link to post
Share on other sites
eternaluxe

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.

Share this post


Link to post
Share on other sites
Crystall

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!

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.