Sign in to follow this  
Followers 0
alansch64

How to test object value ?

4 posts in this topic

Hello,

After hours of searching with no luck, I turn to you for my question.

I'm new to autoit and scripting and recently learning from examples found here in the forum. A true gold mine !

The following script will return the property name of any instance of PNPDeviceID containing "FTDI" (which is a chip used for (USB/RS232) )

Of course on some computer this property name does not exist.

I need to inform the user that the device was not found.

My Question: How can I test "$oItem.Name" to see if it's content is empty and send out a message saying that no device was found ?

I've tried to assign a variable to be able to test it..etc.. but that won't do.

I'm certainly missing on an easy thing that comes from my lack of programing knowledge.. . so thanks in advance for your help.

Local $wbemFlagReturnImmediately= 0x10
Local $wbemFlagForwardOnly   = 0x20
Local $h_wbemFlags = $wbemFlagReturnImmediately + $wbemFlagForwardOnly
$sWMIService = "winmgmts:\\" & @ComputerName & "\root\CIMV2"
$objWMIService = ObjGet($sWMIService)
If IsObj($objWMIService) Then
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PnpEntity WHERE PNPDeviceID LIKE '%FTDI%'", "WQL", $h_wbemFlags)
If IsObj($oItem) Then
    For $oItem in $colItems
    MsgBox(64, "Win32_PnpEntity", $oItem.Name)
    Next
    
    Else
        MsgBox(16, "Error", "Failed to get Win32_PnpEntity.")
    EndIf
Else
    MsgBox(4096, "ERROR", "Failed to connect to WMI at: " & $sWMIService)
EndIf

Share this post


Link to post
Share on other sites



Try

If IsObj($colItems) Then

instead of

If IsObj($oItem) Then


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Try

If IsObj($colItems) Then

instead of

If IsObj($oItem) Then

Thanks !

I was missing the If IsObj to test the value...

Works now !!

Share this post


Link to post
Share on other sites

Glad to help you ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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