BatMan22 Posted March 9, 2019 Share Posted March 9, 2019 Heys guys, I wanted to design something that would run in the startup folder always, that would wait till a iphone is plugged into a phone then launch another application (that too is autoit based). The problem that I have right now, is that I can detect when an iphone is plugged in, but how do I get it to stop launching the app if you close the app but want to leave the phone plugged in? I don't want it to run the program again until the phone is unplugged and plugged back in. Ideas? I was thinking of designing the script to only launch the app once, and restart itself if/when a disconnect of the iphone is detected, but I don't know how to detect a disconnected phone from the computer. Thanks :) Global $latestname = "/Loaderv2.51.exe" Global $foundalready = 0 While 1 Local $vObjWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") $vObjItems = $vObjWMI.ExecQuery('SELECT * FROM Win32_USBHub') If IsObj($vObjItems) Then For $vObjItem In $vObjItems If StringInStr($vObjItem.Description, "Apple") Then If $foundalready = 0 Then $foundalready = 1 IsItStillRunning() Sleep(1000) EndIf EndIf Next EndIf WEnd Func IsItStillRunning() Sleep(1000) Local $cc = WinExists("CydiaLoader") If $cc = 0 Then Local $c = Run(@ScriptDir & $latestname) If $c = 0 Then MsgBox(0, 0, "failed to open cydia impactor, did you rename it?") EndIf EndFunc ;==>IsItStillRunning Link to comment Share on other sites More sharing options...
BatMan22 Posted March 9, 2019 Author Share Posted March 9, 2019 I fixed it so it works but the program calls itself and I'm afraid that it will eventually cause nesting errors? Or cause memory issues if you leave the phone connected for too long.. is there a better fix? expandcollapse popupGlobal $latestname = "/Loaderv2.51.exe" Global $Stillconnected = 0 While 1 Local $vObjWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") $vObjItems = $vObjWMI.ExecQuery('SELECT * FROM Win32_USBHub') If IsObj($vObjItems) Then For $vObjItem In $vObjItems If StringInStr($vObjItem.Description, "Apple") Then If $Stillconnected = 0 Then $Stillconnected = 1 Launcher() StillConnected() Sleep(1000) EndIf EndIf Next Sleep(5000) EndIf WEnd Func Launcher() Sleep(1000) Local $cc = WinExists("CydiaLoader") If $cc = 0 Then Local $c = Run(@ScriptDir & $latestname) If $c = 0 Then MsgBox(0, 0, "failed to open cydia impactor, did you rename it?") EndIf EndFunc ;==>Launcher Func StillConnected() Local $vObjWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") $vObjItems = $vObjWMI.ExecQuery('SELECT * FROM Win32_USBHub') If IsObj($vObjItems) Then For $vObjItem In $vObjItems If StringInStr($vObjItem.Description, "Apple") Then Sleep(10000) StillConnected() EndIf Next EndIf $Stillconnected = 0 EndFunc ;==>StillConnected Link to comment Share on other sites More sharing options...
Nine Posted March 9, 2019 Share Posted March 9, 2019 I think the best approach would be doing something like this : expandcollapse popupOpt ("MustDeclareVars", 1) HotKeySet ("{ESC}","_Exit") Global $latestname = "/Loaderv2.51.exe" While True While Not IsAppleConnected () Sleep (100) Wend Launcher () While IsAppleConnected () Sleep (100) Wend Wend Func _Exit () Exit EndFunc Func IsAppleConnected () Local $vObjWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") Local $vObjItems = $vObjWMI.ExecQuery('SELECT * FROM Win32_USBHub') If not IsObj($vObjItems) Then Exit MsgBox (0,"Error","Not an object") For $vObjItem In $vObjItems If StringInStr($vObjItem.Description, "Apple") Then return True Next Return False EndFunc Func Launcher() If not WinExists("CydiaLoader") Then Local $c = Run(@ScriptDir & $latestname) If $c = 0 Then Exit MsgBox(0, 0, "failed to open cydia impactor, did you rename it?") EndIf EndFunc ;==>Launcher BatMan22 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Exit Posted March 9, 2019 Share Posted March 9, 2019 (edited) Perhaps using _SingleScript() function? You may wait until predecessor ends or kill predecessor or kill own script. _SingleScript.au3 may be found here Edited March 9, 2019 by Exit BatMan22 1 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
BatMan22 Posted March 10, 2019 Author Share Posted March 10, 2019 @Nine Thank you, that's exactly what I wanted to do. Simple, clean and easy. WIsh I could have figured that out by myself, also I never knew that Exit Msg was a thing.. Thanks for that too! Link to comment Share on other sites More sharing options...
Nine Posted March 11, 2019 Share Posted March 11, 2019 2 hours ago, BatMan22 said: @Nine Thank you, that's exactly what I wanted to do. Simple, clean and easy. WIsh I could have figured that out by myself, also I never knew that Exit Msg was a thing.. Thanks for that too! Glad you like it ! “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Bilgus Posted March 11, 2019 Share Posted March 11, 2019 Link to comment Share on other sites More sharing options...
BatMan22 Posted March 11, 2019 Author Share Posted March 11, 2019 16 hours ago, Bilgus said: Yeah I stole some code from there already, I was more confused on how to run a program once per plugin and not to launch the program continuously without getting stuck in that infinite loop of a function calling itself. It seems the simplest answer was to use the return command, which I should have known. Link to comment Share on other sites More sharing options...
Subz Posted March 11, 2019 Share Posted March 11, 2019 This didn't work for me, I had to use Win32_PnPEntity to detect if my phone was plugged in, also if "Cydia Impactor" has a process name would be better to detect then Window title imho. Opt ("MustDeclareVars", 1) HotKeySet ("{ESC}","_Exit") Global $bAppleConnected = False, $bIsAppleConnected = False Global $sFilePath = @ScriptDir Global $sFileName = "Loaderv2.51.exe" While 1 $bIsAppleConnected = IsAppleConnected() If $bAppleConnected <> $bIsAppleConnected Then If $bIsAppleConnected = True Then Launcher() EndIf $bAppleConnected = $bIsAppleConnected Sleep (100) Wend Func _Exit () Exit EndFunc Func IsAppleConnected () Local $vObjWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") Local $vObjItems = $vObjWMI.ExecQuery('SELECT * FROM Win32_PnPEntity') If not IsObj($vObjItems) Then Exit MsgBox (0,"Error","Not an object") For $vObjItem In $vObjItems If StringInStr($vObjItem.Description, "Apple") Then return True Next Return False EndFunc Func Launcher() If ProcessExists($sFileName) Then Return If Run($sFilePath & "\" & $sFileName) = 0 Then Exit MsgBox(0, 0, "failed to open cydia impactor, did you rename it?") EndFunc Link to comment Share on other sites More sharing options...
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