Jump to content
bylly

Go to function at the end of the script instead of exiting

Recommended Posts

Hello this is the code maybe you can figure it out I placed some comments to try and explain what I want

#include <Array.au3>

AnyDeskOpen()

Func AnyDeskOpen()
      Global  $aWinList = WinList("[REGEXPTITLE:(?i)(.*Anydesks*)]")   ;get window name and handle from windows and store into an array
      $asd = $aWinList
      $aExtract = _ArrayExtract($asd)                                   ; beginner babble clean this Sh** up 
      Global $default = _ArrayToString($aExtract, "", 0, 0)
EndFunc

StartWait()                                                     ; check in the array to see how many windows are opened
Func StartWait()
While 1
AnyDeskOpen()

If $Default = 1 Then
   Sleep (3500)
                Else
      Exitloop
   EndIf
WEnd
EndFunc

If $default = "2" Then                                          ; If two windows are opened than someone is trying to connect to that computer and needs a click to accept connection try and click accept Button in the first window and the second one by activating diffrent window handle 


    $extra = _ArrayToString($aWinList, "", 1, 1)
    $sString = StringReplace($extra, "AnyDesk", "")
   $hGUI = $sString
   WinActivate(HWnd($hGUI))
   winmove (HWnd($hGUI), "", 50, 50)
   Mouseclick ("left", 100, 500)


   Sleep (1500)

   $extra = _ArrayToString($aWinList, "", 2, 2)
    $sString = StringReplace($extra, "AnyDesk", "")
   $hGUI = $sString
   WinActivate(HWnd($hGUI))
   winmove (HWnd($hGUI), "", 50, 50)
   Mouseclick ("left", 100, 500)

EndIf


While 1                                                               ;up to here everything seems to work
AnyDeskOpen()                                                           ; while there is a connection there are two AnyDesk windows,  if we close the connection than only one window remains opened and we check the array to see how many values it has
If $Default = 2 Then    
   Sleep (3500)
Else                                                                        ; At this  point the program exits code 0 instead of resseting to function above   
     StartWait()
      Exitloop

   EndIf
WEnd                                                                      ; thank you

 the intent is to keep the program going so it clicks accept again when reconnecting

Share this post


Link to post
Share on other sites

Go to function at the end of the script instead of exiting

If you really want this, please check OnAutoItExitRegister function in AutoIt SciTE's Help file

Edited by Colduction

Share this post


Link to post
Share on other sites

Here is another way, untested (don't have AnyDesk).

#include <Array.au3>
HotKeySet("{ESC}", "_ExitScript")   ;~ Press Escape to Exit script.

Global $g_aAnyDeskSessions[1][2] = WinList("[REGEXPTITLE:(?i)(.*AnyDesk*)]")    ;~ Count number of AnyDesk Windows

AdlibRegister("_AnyDeskSessions")

While 1
    Sleep(100)
WEnd

Func _AnyDeskSessions()
    Local $aAnyDeskSessions = WinList("[REGEXPTITLE:(?i)(.*AnyDesk*)]") ;~ Get number of AnyDesk Windows
    If $aAnyDeskSessions[0][0] = $g_aAnyDeskSessions[0][0] Then Return  ;~ Compare against the global array, no changes return
    Switch $aAnyDeskSessions[0][0]  ;~ AnyDesk Window count has changed
        Case 0
            $g_aAnyDeskSessions = $aAnyDeskSessions ;~ No AnyDesk Windows are open, update global array and return
            Return
        Case 1
            $g_aAnyDeskSessions = $aAnyDeskSessions ;~ 1 AnyDesk Window is open, update global array and return
            Return
        Case Else   ;~ Multiple Windows are open
            For $i = 1 To $aAnyDeskSessions[0][0]   ;~ Loop through all sessions to check if it's been activated by searching the global array for the handle
                If _ArraySearch($g_aAnyDeskSessions, $aAnyDeskSessions[$i][1], 1, 0, 0, 0, 1, 1) = -1 Then
                    WinMove($aAnyDeskSessions[$i][1], "", 150, 150)
                    MouseClick("left", 100, 500)
                EndIf
            Next
            $g_aAnyDeskSessions = $aAnyDeskSessions ;~ Update global array and return
    EndSwitch
EndFunc

Func _ExitScript()
    Exit
EndFunc

 

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By MiKa666
      Hi all,
      I'm developing a tool for exploratively testing another software. For that I wanna cover all the GUI functionality from that software and verify everything works as intended. But now I've a problem which I couldnt solve so far.
      One thing that software I'm testing does, is to load up either a single picture or a series of pictures. Depending on how much pictures got loaded, further actions will be proceeded...
      This loaded pictures are schon within a ToolbarWindow and they're clickable. What I need to know is, how much pictures are in this ToolbarWindow...
      Can anybody provide me a tip on how to achive this?
      Would be amazing!!
      BR,
      Mic
    • By meety
      Hello!
      wingettext function can get the text content of the IE browser page, but the text content of the page cannot be obtained in the chrome browser? What should I do?
    • By DirtyJohny
      Hi everyone.Need rewrite this function how in еxample.
      Original:
      #RequireAdmin #NoTrayIcon Opt("MustDeclareVars",1) Func _a() Local $sls=ObjGet("winmgmts:{impersonationLevel=impersonate," _ &"authenticationLevel=Pkt}!\\"& _ @ComputerName&'\root\wmi'),$lss=$sls.ExecQuery _ ('SELECT * FROM WmiMonitorID'), _ $lll,$sll,$sss="",$lsl,$lls,$i,$z For $z In $lss $lsl=$z.UserFriendlyName For $i=0 To Ubound($lsl)-1 if ($lsl[$i]) Then $lll&=Chr($lsl[$i]) Next $lls=$z.SerialNumberID For $i=0 To Ubound($lls)-1 if ($lls[$i]) Then $sll&=Chr($lls[$i]) Next $sss&="Model"&@TAB&@TAB&": "&$lll&@CR&"Serial Number"&@TAB&": "&$sll&@CR&@CR $lll="" $sll="" Next MsgBox(262144,'Monitors '&$lss.Count,$sss&" "&@CR) $lss=Null $sls=Null EndFunc _a() Example:
      Func _InfoPC() Local $ObjService = ObjGet('winmgmts:{impersonationLevel = impersonate}!\\' & @ComputerName & '\root\cimv2') Local $ObjMB = $ObjService.ExecQuery('SELECT * FROM Win32_BaseBoard', 'WQL', 0x30) If IsObj($ObjService) Then For $objItemMB In $ObjMB $sInfo &= @TAB & 'Motherboard: ...... ' & $objItemMB.Product & @CRLF I'm beginner in this sphere and need  you all speak easy and simply because i'm Russian.Thanks)
    • By Deshanur
      Am trying to automate injecting credential on the login form for all kind of Web application for IE. I know how to identify the form name by viewing the source code and using the method - _IEFormGetObjByName($ie, $form_Name).
      I would like to know how to identify or get the form object for the web app where there is no form name tag for example below, for the is I have used - _IEFormGetCollection($ie, 0) to get the form object.
      My Question is does it work for all kind of application "_IEFormGetCollection($ie, 0)" how to identify Index value? is it always 0? is there any better solution?
      The final solution am looking for is find out form object, get the username, password field and inject credential and submit the form.
      How to find out index value? for the forms which does not have form name field.
      $login_form = _IEFormGetCollection($ie, 0) $email_field = _IEFormElementGetObjByName($login_form, $form_UserName) $pass_field = _IEFormElementGetObjByName($login_form, $form_password) $login_button = _IEFormElementGetObjByName($login_form, $form_submitbutton) _IEFormElementSetValue($email_field, $CmdLine[2]) _IEFormElementSetValue($pass_field, $CmdLine[3]) ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]","{Enter}") OR This works fine if the form has form name. $login_form = _IEFormGetObjByName($ie, $form_Name) $email_field = _IEFormElementGetObjByName($login_form, $form_UserName) $pass_field = _IEFormElementGetObjByName($login_form, $form_password) $login_button = _IEFormElementGetObjByName($login_form, $form_submitbutton) _IEFormElementSetValue($email_field, $CmdLine[2]) _IEFormElementSetValue($pass_field, $CmdLine[3]) ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]","{Enter}")
    • By JuanFelipe
      Hello guys!
      I have a problem with a script, in the past I made a program and it worked perfect, I recently used it again and it already stands still in one step, the problem is a Javascript event that changed but now I cannot execute it.
       
      <td colspan="2" align="center"><input type="button" id="Buscar" name="Buscar" value="Buscar" onclick="javascript:enviarForma(document.obtenercasosPersonaPorDocumento,'0');" class="boton"></td>  
      Previously I used this code and it worked, but now it does nothing
      $botonconsulta = _IEGetObjByName($oIE,"Buscar") _IEAction($botonconsulta, 'click') _IELoadWait($oIE)  
      Now I have tried the following codes but none works.
       
      ;==================== 1 _IEHeadInsertEventScript($oIE, "document", "onclick", "javascript:enviarForma(document.obtenercasosPersonaPorDocumento,'0');") ControlClick("SUPER CELAC", "", "[CLASS:Internet Explorer_Server; INSTANCE:1]") _IELoadWait($oIE) ;==================== 2 $forma = $oIE.document.obtenercasosPersonaPorDocumento $oIE.Navigate("JavaScript:enviarForma("&$forma&",""0"");") _IELoadWait($oIE) ;==================== 3 $boton = _IEGetObjById($oIE, "Buscar") $boton.document.parentwindow.execScript("enviarForma(document.obtenercasosPersonaPorDocumento,'0');", "javascript") I hope you can guide me, because I think the error is in the parameters that the javascript function receives but I don't know how to send it, here I leave the first part of the JavaScript function.
      function enviarForma(frm,tipoForma){ var bExisteDatoConsulta = false; var bError=true; var mensajeError=""; switch (tipoForma) { //--Forma documento case "0": if (validar_campo_no_vacio_no_print(frm.numeroDocumento)) { if (!isNum(frm.numeroDocumento.value)) { bError = false; mensajeError += "El número de documento debe ser un valor numérico\n"; } bExisteDatoConsulta = true; } else { mensajeError += "Debe digitar un número de documento\n"; } break;  Thanks!
×
×
  • Create New...