Collins Posted May 30, 2018 Posted May 30, 2018 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
AutoBert Posted May 30, 2018 Posted May 30, 2018 (edited) you can use a loop for solving your problem: Do ... Until Edited May 30, 2018 by AutoBert
Collins Posted May 31, 2018 Author Posted May 31, 2018 (edited) 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 May 31, 2018 by Collins problem solved
Bilgus Posted May 31, 2018 Posted May 31, 2018 (edited) 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 May 31, 2018 by Bilgus
Collins Posted May 31, 2018 Author Posted May 31, 2018 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
Bilgus Posted May 31, 2018 Posted May 31, 2018 sorry that should be $iDeviceState = BitAnd($iDeviceState, BitNot($eDevicePlugged))
Collins Posted June 2, 2018 Author Posted June 2, 2018 On 5/31/2018 at 9:32 PM, Bilgus said: sorry that should be $iDeviceState = BitAnd($iDeviceState, BitNot($eDevicePlugged)) Thank you
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now