Jump to content

How can i detect my iPhone anytime i connect it


Recommended Posts

From search and help on here. I am able to detect my iPhone when its plugged in and i run my script..

I want to know how i can detect my iPhone anytime i remove and insert it back without having to run the script again.

 

Below is the code in detecting 

#include <MsgBoxConstants.au3>

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

$WMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
$aItems = $WMI.ExecQuery("SELECT * FROM Win32_PnPEntity", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)


    If IsObj($aItems) Then
        For $item In $aItems
            If StringInStr($item.Description, "iPhone") Then
                Msgbox($MB_SYSTEMMODAL,"device found","Your device is found" & $item.Description )
                ;Do Stuff
            EndIf
        Next
    Else
        Msgbox($MB_SYSTEMMODAL,"WMI Output","No WMI Objects Found for class: " & "Win32_PnPEntity" )
    Endif

 

Link to comment
Share on other sites

Thanks for the help. I have been able to do it. But i want the message box to run once anytime the device is connected .. 

The message box keeps showing until i disconnect the phone...

 

 

Below is the script

#include <MsgBoxConstants.au3>

Do
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

$WMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
$aItems = $WMI.ExecQuery("SELECT * FROM Win32_PnPEntity", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)



    If IsObj($aItems) Then
        For $item In $aItems
            If StringInStr($item.Description, "iPhone") Then
                Msgbox($MB_SYSTEMMODAL,"device found","Your device is found " & $item.Description )


            EndIf
        Next
    Else
        Msgbox($MB_SYSTEMMODAL,"WMI Output","No WMI Objects Found for class: " & "Win32_PnPEntity" )
    Endif

    Until False

 

Edited by Collins
problem solved
Link to comment
Share on other sites

either set a flag or exit the loop..

#include <MsgBoxConstants.au3>
Global Enum $eDeviceUnplugged = 0, $eDevicePlugged, $eDeviceConnected
Global $iDeviceState = $eDeviceUnplugged

Do
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

$WMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
$aItems = $WMI.ExecQuery("SELECT * FROM Win32_PnPEntity", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)



    If IsObj($aItems) Then
        $iDeviceState = BitAnd($iDeviceState, BitNot($eDevicePlugged)) ;Remove Plugged flag but leave Connected flag if it exists
        For $item In $aItems
            If StringInStr($item.Description, "iPhone") Then
                
                if Not BitAnd($iDeviceState, $eDeviceConnected) Then
                    Msgbox($MB_SYSTEMMODAL,"device found","Your device is found " & $item.Description )
                    $iDeviceState = BitOr($eDeviceConnected, $eDevicePlugged) ;Keep message from appearing again till device unplugged + re-plugged
                Else
                    $iDeviceState = BitOr($iDeviceState, $eDevicePlugged) ;Message has already been shown and device is still connected
                Endif
                ExitLoop ;We are done here no need to check anything else
            EndIf
        Next
        if Not BitAnd($iDeviceState, $eDeviceConnected) Then $iDeviceState = $eDeviceUnplugged ;Device not found reset to unplugged state 
    Else
        Msgbox($MB_SYSTEMMODAL,"WMI Output","No WMI Objects Found for class: " & "Win32_PnPEntity" )
    Endif

Until False

 

Edited by Bilgus
Link to comment
Share on other sites

Thank you for your help.. I am grateful. I am totally new to autoit..

I am having another problem here. when i try to run , it says

 

 

 ==> Incorrect number of parameters in function call.:
$iDeviceState = BitNot($iDeviceState, $eDevicePlugged)
$iDeviceState = ^ ERROR
>Exit code: 1    Time: 0.5109

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