kevev Posted December 6, 2009 Share Posted December 6, 2009 Hello Everyone. It has been a long time since I touched any of my AutoIt code. I am having trouble checking to see if 2 processes are running. $oPID needs to be checked to see if a PID is returned. If I start openvpn.exe manually then start the gui I will see it is running. Then select stop and the status will show stopped. But If I start the GUI with the service stopped and click start the status does not show the service is running. $aPID output is checked for the string "unknown" somewhere is all the output of the adb.exe command. This is having the same issue as $oPID except it is worse. I cant get anychange in the status in the GUI even if the service is started first. I am not seeing the status in my gui change when I kill the processes and start them with the buttons I programmed. The code is an OpenSource Christmas gift for the android users @ the xda-developers.com community. So I would like to get it completed as soon as possible. Thank You in advance. expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=icon.ico #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Comment=No Warranties or Guarantees are implied or offered by the Author or Distributor. All code covered by "GNU GENERAL PUBLIC LICENSE V2, June 1991". #AutoIt3Wrapper_Res_Description=A frontend for the "Great" Android usb tethering package by aziwoqpd(jperry) "azilink". #AutoIt3Wrapper_Res_Fileversion=1.0.2.15 #AutoIt3Wrapper_Res_FileVersion_AutoIncrement=y #AutoIt3Wrapper_Res_LegalCopyright=http://kevev.net/ #AutoIt3Wrapper_Res_SaveSource=y #AutoIt3Wrapper_Res_Language=1033 #AutoIt3Wrapper_Au3Check_Stop_OnWarning=y #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; This script controlls connect/disconnect of AziLink in Windows; #include <Array.au3> #include <Constants.au3> #include <GuiConstantsEx.au3> #include <Misc.au3> #include <Process.au3> Opt("GUIOnEventMode", 1) ; Only run one instance If _Singleton("azilink-gui", 1) = 0 Then Exit EndIf ; VARIABLES $mainwindows = GUICreate("azilink-gui", 180, 90) GUISetOnEvent($GUI_EVENT_CLOSE, "exititem") $Filemenu = GUICtrlCreateMenu("File") $installitem = GUICtrlCreateMenuItem("Install apk...", $Filemenu) GUICtrlSetOnEvent($installitem, "Installitem") $separator1 = GUICtrlCreateMenuItem("", $Filemenu) $exititem = GUICtrlCreateMenuItem("Exit", $Filemenu) GUICtrlSetOnEvent($exititem, "exititem") $helpmenu = GUICtrlCreateMenu("Help") $readmeitem = GUICtrlCreateMenuItem("Readme", $helpmenu) GUICtrlSetOnEvent($readmeitem, "readmeitem") $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu) GUICtrlSetOnEvent($aboutitem, "aboutitem") $connectbutton = GUICtrlCreateButton("Connect", 10, 40, 70, 20) GUICtrlSetOnEvent($connectbutton, "connectbutton") $disconnectbutton = GUICtrlCreateButton("Disconnect", 100, 40, 70, 20) GUICtrlSetOnEvent($disconnectbutton, "disconnectbutton") $adb = "adb\adb.exe" & " forward" & " tcp:41927" & " tcp:41927" $openvpn = "openvpn --config azilink.ovpn" $oPID = ProcessExists("openvpn.exe") $aPID = ProcessExists("adb.exe") $adbinstall = "adb\adb.exe" & " install" & " azilink-2.0.2.apk" & " &" & " pause" $DeviceDetect = "adb\adb.exe" & " get-state" $Readme = "notepad.exe azilink-gui_howto.txt" ;$DetectOut = _RunWait($DeviceDetect, "", @SW_HIDE, 2) ;$DetectOut = StringInStr($DeviceDetect, "tcp:4192") $DetectOut = StringInStr($DeviceDetect, "unknown") GUISetState(@SW_SHOW) ; FUNCTIONS Func _RunWait($sFilename, $sWorkingdir = "", $sFlag = "", $iIOFlag = "", $iTimeOut = 0) Local $pid = Run($sFilename, $sWorkingdir, $sFlag, $iIOFlag) If $iTimeOut Then $timer = TimerInit() While ProcessExists($pid) Sleep(50) If $iTimeOut Then If TimerDiff($timer) >= $iTimeOut Then ExitLoop EndIf WEnd If ProcessExists($pid) Then ProcessClose($pid) If StderrRead($pid) <> "" Then Return SetError(2, 0, StderrRead($pid)) Return SetError(3, 0, StdoutRead($pid)) EndIf If StderrRead($pid) <> "" Then Return SetError(1, 0, StderrRead($pid)) Return StdoutRead($pid) EndFunc ;==>_RunWait Func installitem() $pid = ProcessExists("adb.exe") While $pid ProcessClose($pid) $pid = ProcessExists("adb.exe") WEnd $file = RunWait(@ComSpec & " /c " & $adbinstall) EndFunc ;==>installitem Func readmeitem() Run($Readme, "", @SW_SHOWDEFAULT) EndFunc ;==>readmeitem Func aboutitem() MsgBox(0, "About", "Created by kevin evans (http://kevev.net) for AziLink (Jim Perry http://code.google.com/p/azilink/) GPL v2") EndFunc ;==>aboutitem Func connectbutton() _RunWait($adb, "", @SW_HIDE, 2) Run($openvpn, "", @SW_HIDE) EndFunc ;==>connectbutton Func disconnectbutton() $oPID = ProcessExists("openvpn.exe") If $oPID Then While $oPID ProcessClose($oPID) $oPID = ProcessExists("openvpn.exe") WEnd EndIf $aPID = ProcessExists("adb.exe") If $aPID Then While $aPID ProcessClose($aPID) $aPID = ProcessExists("adb.exe") WEnd EndIf EndFunc ;==>disconnectbutton Func exititem() disconnectbutton() Exit EndFunc ;==>exititem While 1 If Not $oPID Then Run($adb, "", @SW_HIDE, 2) EndIf If $oPID Then GUICtrlCreateLabel("(Link Enabled)", 30, 15, 110, 15) Else GUICtrlCreateLabel("(Link Disabled)", 30, 15, 110, 15) EndIf If $DetectOut <> 0 Then ;If $DetectOut Then GUICtrlCreateLabel("(Device Detected)", 30, 1, 110, 15) Else GUICtrlCreateLabel("(Device Not Detected!)", 30, 1, 110, 15) EndIf Sleep(1000) ; Idle around WEnd Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 6, 2009 Share Posted December 6, 2009 You didn't save the new PID to $oPID: While 1 If Not $oPID Then $oPID = Run($adb, "", @SW_HIDE, 2) ; ... WEnd Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
kevev Posted December 8, 2009 Author Share Posted December 8, 2009 You didn't save the new PID to $oPID: While 1 If Not $oPID Then $oPID = Run($adb, "", @SW_HIDE, 2) ; ... WEnd Thank You PsaltyDS. I don't think that I explained my self very well. Your tip did lead me in the correct direction. I am now able to monitor the adb.exe & openvpn.exe processes. While 1 $oPID = ProcessExists("openvpn.exe") $aPID = ProcessExists("adb.exe") If Not $oPID Then Run($adb, "", @SW_HIDE, 2) EndIf If $oPID Then GUICtrlCreateLabel("(Link Enabled)", 30, 15, 110, 15) Else GUICtrlCreateLabel("(Link Disabled)", 30, 15, 110, 15) EndIf If $DetectOut <> 0 Then ;If $DetectOut Then GUICtrlCreateLabel("(Device Detected)", 30, 1, 110, 15) Else GUICtrlCreateLabel("(Device Not Detected!)", 30, 1, 110, 15) EndIf Sleep(1000) ; Idle around WEnd Now I need to figure out how to detect the device an easy way. I tried reading the output from the 'adb.exe get-state' command. But the output is different depending on whether adb.exe was already running, the port forwarding is already enabled, the divice is properly connected. So, I am looking into detecting the device in the "Device Manager" or the registry or another way. Does anyone have a good way to detect a device driver being used even if it is by different devices? Link to comment Share on other sites More sharing options...
kevev Posted December 8, 2009 Author Share Posted December 8, 2009 I decided to just read the output of adb.exe . It was not that difficult. My app is complete. The code is GPL2 if anyone wants to use it. I will be posting it to a few Android sites. expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=icon.ico #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Comment=No Warranties or Guarantees are implied or offered by the Author or Distributor. All code covered by "GNU GENERAL PUBLIC LICENSE V2, June 1991". #AutoIt3Wrapper_Res_Description=A frontend for the "Great" Android usb tethering package by aziwoqpd(jperry) "azilink". #AutoIt3Wrapper_Res_Fileversion=1.0.2.16 #AutoIt3Wrapper_Res_FileVersion_AutoIncrement=y #AutoIt3Wrapper_Res_LegalCopyright=http://kevev.net/ #AutoIt3Wrapper_Res_SaveSource=y #AutoIt3Wrapper_Res_Language=1033 #AutoIt3Wrapper_Au3Check_Stop_OnWarning=y #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; This script controlls connect/disconnect of AziLink in Windows; #include <Array.au3> #include <Constants.au3> #include <GuiConstantsEx.au3> #include <Misc.au3> #include <Process.au3> Opt("GUIOnEventMode", 1) ; Only run one instance If _Singleton("azilink-gui", 1) = 0 Then Exit EndIf ; VARIABLES $mainwindows = GUICreate("azilink-gui", 180, 90) GUISetOnEvent($GUI_EVENT_CLOSE, "exititem") $Filemenu = GUICtrlCreateMenu("File") $installitem = GUICtrlCreateMenuItem("Install apk...", $Filemenu) GUICtrlSetOnEvent($installitem, "Installitem") $separator1 = GUICtrlCreateMenuItem("", $Filemenu) $exititem = GUICtrlCreateMenuItem("Exit", $Filemenu) GUICtrlSetOnEvent($exititem, "exititem") $helpmenu = GUICtrlCreateMenu("Help") $readmeitem = GUICtrlCreateMenuItem("Readme", $helpmenu) GUICtrlSetOnEvent($readmeitem, "readmeitem") $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu) GUICtrlSetOnEvent($aboutitem, "aboutitem") $connectbutton = GUICtrlCreateButton("Connect", 10, 40, 70, 20) GUICtrlSetOnEvent($connectbutton, "connectbutton") $disconnectbutton = GUICtrlCreateButton("Disconnect", 100, 40, 70, 20) GUICtrlSetOnEvent($disconnectbutton, "disconnectbutton") $LinkStatusLast = "" $LinkLabel = "1" $DeviceStatusLast = "" $DeviceLabel = "1" $adb = "adb\adb.exe" & " forward" & " tcp:41927" & " tcp:41927" $openvpn = "openvpn --config azilink.ovpn" $adbinstall = "adb\adb.exe" & " install" & " azilink-2.0.2.apk" & " &" & " pause" $DeviceDetect = "adb\adb.exe" & " get-state" $DetectOut = _RunWait($DeviceDetect, "", @SW_HIDE, 2) GUISetState(@SW_SHOW) ; FUNCTIONS Func _RunWait($sFilename, $sWorkingdir = "", $sFlag = "", $iIOFlag = "", $iTimeOut = 0) Local $pid = Run($sFilename, $sWorkingdir, $sFlag, $iIOFlag) If $iTimeOut Then $timer = TimerInit() While ProcessExists($pid) Sleep(50) If $iTimeOut Then If TimerDiff($timer) >= $iTimeOut Then ExitLoop EndIf WEnd If ProcessExists($pid) Then ProcessClose($pid) If StderrRead($pid) <> "" Then Return SetError(2, 0, StderrRead($pid)) Return SetError(3, 0, StdoutRead($pid)) EndIf If StderrRead($pid) <> "" Then Return SetError(1, 0, StderrRead($pid)) Return StdoutRead($pid) EndFunc ;==>_RunWait Func installitem() $pid = ProcessExists("adb.exe") While $pid ProcessClose($pid) $pid = ProcessExists("adb.exe") WEnd $file = RunWait(@ComSpec & " /c " & $adbinstall) EndFunc ;==>installitem Func readmeitem() $Readme = FileOpen("azilink-gui_howto.txt", 0) If $Readme = -1 Then MsgBox(0, "Error", "Unable to open azilink-gui_howto.txt") Exit EndIf While 1 $chars = FileRead($Readme) If @error = -1 Then ExitLoop MsgBox(0, "Char read:", $chars) WEnd FileClose($Readme) EndFunc ;==>readmeitem Func aboutitem() MsgBox(0, "About", "Created by kevin evans (http://kevev.net) for AziLink (Jim Perry http://code.google.com/p/azilink/) GPL v2") EndFunc ;==>aboutitem Func connectbutton() _RunWait($adb, "", @SW_HIDE, 2) Run($openvpn, "", @SW_HIDE) EndFunc ;==>connectbutton Func disconnectbutton() $oPID = ProcessExists("openvpn.exe") If $oPID Then While $oPID ProcessClose($oPID) $oPID = ProcessExists("openvpn.exe") WEnd EndIf $aPID = ProcessExists("adb.exe") If $aPID Then While $aPID ProcessClose($aPID) $aPID = ProcessExists("adb.exe") WEnd EndIf EndFunc ;==>disconnectbutton Func exititem() disconnectbutton() Exit EndFunc ;==>exititem While 1 $oPID = ProcessExists("openvpn.exe") $aPID = ProcessExists("adb.exe") $DetectOut = _RunWait($DeviceDetect, "", @SW_HIDE, 2) If Not $oPID Then Run($adb, "", @SW_HIDE, 2) EndIf If $oPID Then $LinkStatus = "(Link Enabled)" Else $LinkStatus = "(Link Disabled)" EndIf If $LinkStatusLast <> $LinkStatus Then $LinkLabel = GUICtrlCreateLabel($LinkStatus, 30, 15, 110, 15) $LinkStatusLast = $LinkStatus EndIf If $DetectOut = "device" & @CRLF Then $DeviceStatus = "(Device Detected)" Else $DeviceStatus = "(Device Not Detected!)" EndIf If $DeviceStatusLast <> $DeviceStatus Then $DeviceLabel = GUICtrlCreateLabel($DeviceStatus, 30, 1, 110, 15) $DeviceStatusLast = $DeviceStatus EndIf Sleep(1500) ; Idle around WEnd 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