Jump to content

How to test object value ?


alansch64
 Share

Recommended Posts

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
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...