Sign in to follow this  
Followers 0
eternaluxe

using $var1.$var in expression

5 posts in this topic

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



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

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

#4 ·  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!

Share this post


Link to post
Share on other sites

Awesmoe! Thanks so much!

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