Jump to content
Sign in to follow this  
alientorress

Dial-In Server with AutoIt-Need advises to improve it

Recommended Posts

alientorress

Hello There.

This is my first Project with AutoIt and i will love to hear some advises so i can make my code better.

Is a Dial-In server on WinXP:

- I use a CallerID Software then when the rigth number dial-in I run the AutoIt script i made(I do this because otherwise if i always have the incoming connection created when someone call my home phone the modem will pick up the call.).

- What the script do:

- Once The CallerID software run the AutoIt script, AutoIt script close CallerID software because otherwise the RASMAN can't take care of the incoming connection because the CallerID software keep using the TAPI service or device...

- Open Network Connection

- Open New Connection Wizard and do all the Steps to finish that Incoming Connection(Here on this Steps i make lots of error check because this software i will use also on some unattenden remote servers...).

- Wait 35 seconds so the incoming connection is complete.(If not complete then Delete Incoming Connection)

- Then search on SysTray tooltips for the incoming connection name(is the only good way i found to do this on WinXP because making ping is not a good way because of firewalls on client side.)(I can't find any other good way to do this.)(I use this function from another guy on this forum and i made some changes credits for him...)

- Once the connection is established then check if the client make any connection to my Mail Server(POP3 or SMTP) i use netstat -anop TCP stdout and read it to an array and parse that(there is a better way? please letme know.)

- IF the client don't make any connection to my mail server i delete de incoming connection otherwise wait until the client finish the connection or for a maximun time of 16minutes so so.

- Delete de Incoming Connection and Restore de CallerID Software.

All this is working but i will love to hear some advises and also i will like to improve this, i was thinking about:

- Just keep incoming connection created and stop and start rasman service but this service is really problematic and don't stop in the way it should and sometimes don't stop at all...

- Other thing i was missing was to create incoming connection and then just check modem box or not depent on what i want to do...

- PLEASE any other idea or anyother way to do this and make it better and faster with less steps?

Here the code:

#cs
Script de AutoIt V3
Nombre: AceptarConexion
Version: 2.1.0
Autor:TheBug2k5
Date: 14-Enero-2012
Time: 7:40PM
Notas: Working so far.
To Do:
- Improve ErrorChecking Funtions.
- Slowly change everything to use ControlCommands and ControlSend methods.
- Add Code Comments.
#ce
; Includes
#include <file.au3>
#include <Process.au3>
#Include <GuiToolBar.au3>
Global $hSysTray_Handle, $ConexExist
Global $conexname = "gam"
Global $hitcounter = 0
Global $winwait = 0
Global $conbreak = 0
Global $delcon = 0
Global $conectime = 0
Global $conexyes = 0
$param1 = $CmdLine[1]
UnlockCloseP()
WriteLog($param1)
CreaConex()
If $delcon = 0 Then
  CheckAndDelConex()
  WriteLogEnd($param1)
  RestoreSoft()
  _RefreshSystemTray()
  Exit
Else
  WriteLogError($param1)
  RestoreSoft()
  _RefreshSystemTray()
  Exit
EndIf

Func UnlockCloseP()
If ProcessExists("CallClerk.exe") Then
ProcessClose("CallClerk.exe")
EndIf
Send("#m")
Sleep(1000)
EndFunc
Func WriteLogErrorFatal($infoid)
FileOpen(@ScriptDir & "\connect.log", 1)
$handle = FileOpen(@ScriptDir & "\connect.log", 1)
_FileWriteLog(@ScriptDir & "\connect.log","Error Fatal La PC se va a Reiniciar: "&$infoid)
FileClose($handle)
EndFunc
Func WriteLogError($infoid)
FileOpen(@ScriptDir & "\connect.log", 1)
$handle = FileOpen(@ScriptDir & "\connect.log", 1)
_FileWriteLog(@ScriptDir & "\connect.log","Error Procesando:     "&$infoid)
FileClose($handle)
EndFunc
Func WriteLog($infoid)
FileOpen(@ScriptDir & "\connect.log", 1)
$handle = FileOpen(@ScriptDir & "\connect.log", 1)
_FileWriteLog(@ScriptDir & "\connect.log","Se ha Conectado:   "&$infoid)
FileClose($handle)
EndFunc
Func WriteLogEnd($infoid)
FileOpen(@ScriptDir & "\connect.log", 1)
$handle = FileOpen(@ScriptDir & "\connect.log", 1)
_FileWriteLog(@ScriptDir & "\connect.log","Se ha Desconectado:   "&$infoid)
FileClose($handle)
EndFunc
; FUNCION PARA CREAR LA CONEXION ENTRANTE
Func CreaConex()
Run("RUNDLL32.EXE SHELL32.DLL,Control_RunDLL ncpa.cpl", "")
ActiveConnectRed()
Sleep(500)
Send("{ALT}ax")
CheckWin()
ActiveHit1()
CheckWinSelect()
ActiveHit2()
CheckWin()
ActiveHit3()
CheckWin()
ActiveHit4()
CheckWin()
ActiveHit5()
CheckWin()
ActiveHit6()
CheckWin()
ActiveHit7()
CheckWin()
ActiveHitEnd()
WinClose("Conexiones de red")
$conexion = 0
While Get_ConexExist($conexname) = 0
  Sleep(500)
  _RefreshSystemTray()
  $conexion = $conexion + 1
  If $conexion >= 35 Then
   DelConex()
   ExitLoop
  Else
   ContinueLoop
  EndIf
WEnd
EndFunc
Func Conected()
If FileExists(@ScriptDir&"-Status.txt") Then
  FileDelete(@ScriptDir&"-Status.txt")
EndIf
_RunDOS('netstat -anop TCP > ' & @ScriptDir&"-Status.txt")
Local $aRecords
_FileReadToArray(@ScriptDir&"-Status.txt",$aRecords)
$pcname = @ComputerName
For $x = 1 to $aRecords[0]
  If ( StringInStr($aRecords[$x], "192.168.0.1"&":25") OR _
  ( StringInStr($aRecords[$x], "192.168.0.1"&":110") ) AND _
  StringInStr($aRecords[$x], "ESTABLISHED")) _
  Then
  $conexyes = 1
  Else
   $conexyes = 0
  EndIf
Sleep(50)
Next
EndFunc
Func CheckConexMail()
If Get_ConexExist($conexname) = 0 AND $delcon = 0 Then
  DelConex()
EndIf
While Get_ConexExist($conexname) <> 0
  Conected()
  If $conexyes <> 0 Then
   Sleep(500)
   $conbreak = $conbreak + 1
   If $conbreak >= 1800 AND $delcon = 0 Then
    DelConex()
    ExitLoop
   Else
    If Get_ConexExist($conexname) <> 0 Then
     CheckConexMail()
    ElseIf $delcon = 0 Then
     DelConex()
    ExitLoop
    EndIf
   EndIf
  Else
   Sleep(500)
   $conectime = $conectime + 1
   If $conectime >= 60 AND $delcon = 0 Then
    DelConex()
    ExitLoop
   Else
    CheckConexMail()
   EndIf
  EndIf
WEnd
EndFunc
Func OnError()
$counter3 = 0
$oncounter1 = 0
If WinExists("Asistente para conexión nueva") Then
  While WinExists("Asistente para conexión nueva")
  WinKill("Asistente para conexión nueva")
  Sleep(500)
  $counter3 = $counter3 + 1
   If $counter3 >= 240 Then
    WriteLogErrorFatal($param1)
    Shutdown (18)
    Exit
   Else
    ContinueLoop
   EndIf
  WEnd
Else
  While WinExists("Conexiones de red")
   WinKill("Conexiones de red")
   Sleep(500)
   $oncounter1 = $oncounter1 + 1
   If $oncounter1 >= 240 Then
    WriteLogErrorFatal($param1)
    Shutdown (18)
    Exit
   Else
    ContinueLoop
   EndIf
  WEnd
EndIf
$on2counter1 = 0
If WinExists ("Conexiones de red") Then
  While WinExists("Conexiones de red")
   WinKill("Conexiones de red")
   Sleep(500)
   $on2counter1 = $on2counter1 + 1
   If $on2counter1 >= 240 Then
    WriteLogErrorFatal($param1)
    Shutdown (18)
    Exit
   Else
    ContinueLoop
   EndIf
  WEnd
EndIf
WriteLogErrorFatal($param1)
Shutdown (18)
Exit
EndFunc
Func CheckWin()
$counter1 = 0
$counter2 = 0
  While Not WinExists("Asistente para conexión nueva")
   Sleep(500)
   $counter1 = $counter1 + 1
   If $counter1 >= 240 Then
    OnError()
    ExitLoop
   Else
    ContinueLoop
   EndIf
  WEnd
  If WinExists("Asistente para conexión nueva") Then
   While Not WinActive("Asistente para conexión nueva")
    WinActivate("Asistente para conexión nueva")
    Sleep(500)
    $counter2 = $counter2 + 1
    If $counter2 >= 240 Then
     OnError()
     ExitLoop
    Else
     ContinueLoop
    EndIf
   WEnd
  EndIf
Sleep(500)
EndFunc
Func CheckWinSelect()
$counter4 = 0
$counter5 = 0
$counter6 = 0
While Not WinExists("Asistente para conexión nueva")
  Sleep(500)
  $counter4 = $counter4 + 1
  If $counter4 >= 240 Then
   OnError()
   ExitLoop
  Else
   ContinueLoop
  EndIf
WEnd
If WinExists("Asistente para conexión nueva") Then
  While Not WinActive("Asistente para conexión nueva")
   WinActivate("Asistente para conexión nueva")
   Sleep(500)
   $counter5 = $counter5 + 1
   If $counter5 >= 240 Then
    OnError()
    ExitLoop
   Else
    ContinueLoop
   EndIf
  WEnd
  While Not ControlCommand('Asistente para conexión nueva', '', '[CLASS:Button; INSTANCE:4]', 'IsEnabled', '')
   Sleep(500)
   $counter6 = $counter6 + 1
   If $counter6 >= 240 Then
    OnError()
    ExitLoop
   Else
    ContinueLoop
   EndIf
  WEnd
ControlSend("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:4]", "{SPACE}")
Sleep(500)
EndIf
EndFunc
Func ActiveHit1()
If  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:2]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:2]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:4]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:4]", "IsVisible", "") Then
  ControlFocus("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:2]")
  Sleep(50)
  Send("{ENTER}")
  Do
   Sleep(500)
   $winwait = $winwait + 1
   If $winwait >= 40 Then
    CreaConex()
    ExitLoop
   EndIf
  Until WinExists("Asistente para conexión nueva")
  $winwait = 0
Else
  Sleep(500)
  $hitcounter = $hitcounter + 1
  If $hitcounter >= 240 Then
   OnError()
  Else
   ActiveHit1()
  EndIf
EndIf
EndFunc

Func ActiveHit2()
If  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:6]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:6]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:5]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:5]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:8]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:8]", "IsVisible", "") Then
  ControlFocus("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:6]")
  Sleep(50)
  Send("{ENTER}")
  Do
   Sleep(500)
   $winwait = $winwait + 1
   If $winwait >= 40 Then
    CreaConex()
    ExitLoop
   EndIf
  Until WinExists("Asistente para conexión nueva")
  $winwait = 0
Else
  Sleep(500)
  $hitcounter = $hitcounter + 1
  If $hitcounter >= 240 Then
   OnError()
  Else
   ActiveHit2()
  EndIf
EndIf
EndFunc

Func ActiveHit3()
If  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:8]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:8]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:7]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:7]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:10]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:10]", "IsVisible", "") Then
  ControlFocus("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:8]")
  Sleep(50)
  Send("{ENTER}")
  Do
   Sleep(500)
   $winwait = $winwait + 1
   If $winwait >= 40 Then
    CreaConex()
    ExitLoop
   EndIf
  Until WinExists("Asistente para conexión nueva")
  $winwait = 0
Else
  Sleep(500)
  $hitcounter = $hitcounter + 1
  If $hitcounter >= 240 Then
   OnError()
  Else
   ActiveHit3()
  EndIf
EndIf
EndFunc
Func ActiveHit4()
If  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:9]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:9]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:8]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:8]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:11]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:11]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:1]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:1]", "IsVisible", "") Then
  ControlFocus("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:9]")
  Sleep(50)
  Send("{ENTER}")
  Do
   Sleep(500)
   $winwait = $winwait + 1
   If $winwait >= 40 Then
    CreaConex()
    ExitLoop
   EndIf
  Until WinExists("Asistente para conexión nueva")
  $winwait = 0
Else
  Sleep(500)
  $hitcounter = $hitcounter + 1
  If $hitcounter >= 240 Then
   OnError()
  Else
   ActiveHit4()
  EndIf
EndIf
EndFunc
Func ActiveHit5()
If  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:11]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:11]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:10]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:10]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:13]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:13]", "IsVisible", "") Then
  ControlFocus("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:11]")
  Sleep(50)
  Send("{ENTER}")
  Do
   Sleep(500)
   $winwait = $winwait + 1
   If $winwait >= 40 Then
    CreaConex()
    ExitLoop
   EndIf
  Until WinExists("Asistente para conexión nueva")
  $winwait = 0
Else
  Sleep(500)
  $hitcounter = $hitcounter + 1
  If $hitcounter >= 240 Then
   OnError()
  Else
   ActiveHit5()
  EndIf
EndIf
EndFunc
Func ActiveHit6()
If  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:14]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:14]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:1]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:1]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:2]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:2]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:3]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:3]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:13]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:13]", "IsVisible", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:16]", "IsEnabled", "") AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:16]", "IsVisible", "") Then
  ControlFocus("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:14]")
  Sleep(50)
  Send("{ENTER}")
  Do
   Sleep(500)
   $winwait = $winwait + 1
   If $winwait >= 40 Then
    CreaConex()
    ExitLoop
   EndIf
  Until WinExists("Asistente para conexión nueva")
  $winwait = 0
Else
  Sleep(500)
  $hitcounter = $hitcounter + 1
  If $hitcounter >= 240 Then
   OnError()
  Else
   ActiveHit6()
  EndIf
EndIf
EndFunc
Func ActiveHit7()
If  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:17]", "IsEnabled" ) AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:17]", "IsVisible" ) AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:1]", "IsEnabled" ) AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:1]", "IsVisible" ) AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:3]", "IsEnabled" ) AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:3]", "IsVisible" ) AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:16]", "IsEnabled" ) AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:16]", "IsVisible" ) AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:19]", "IsEnabled" ) AND _
  ControlCommand("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:19]", "IsVisible" ) Then
  ControlFocus("Asistente para conexión nueva", "", "[CLASS:Button; INSTANCE:17]")
  Sleep(50)
  Send("{ENTER}")
  Do
   Sleep(500)
   $winwait = $winwait + 1
   If $winwait >= 40 Then
    CreaConex()
    ExitLoop
   EndIf
  Until WinExists("Asistente para conexión nueva")
  $winwait = 0
Else
  Sleep(500)
  $hitcounter = $hitcounter + 1
  If $hitcounter >= 240 Then
   OnError()
  Else
   ActiveHit7()
  EndIf
EndIf
EndFunc
Func ActiveHitEnd()
If  ControlCommand('Asistente para conexión nueva', '', 'Finalizar', 'IsEnabled', '') AND _
  ControlCommand('Asistente para conexión nueva', '', 'Finalizar', 'IsVisible', '') Then
  ControlSend("Asistente para conexión nueva", "", "Finalizar", "{ENTER}")
  Do
   Sleep(500)
   $winwait = $winwait + 1
   If $winwait >= 40 Then
    CreaConex()
    ExitLoop
   EndIf
  Until WinExists("Asistente para conexión nueva")
  $winwait = 0
EndIf
While WinExists('Asistente para conexión nueva')
  Sleep(500)
  $hitcounter = $hitcounter + 1
  If $hitcounter >= 240 Then
   OnError()
   ExitLoop
  Else
   ContinueLoop
  EndIf
WEnd
EndFunc
Func ActiveConnectRed()
$counterred1 = 0
$counterred2 = 0
  While Not WinExists("[CLASS:CabinetWClass]","Conexiones de red")
   Sleep(500)
   $counterred1 = $counterred1 + 1
   If $counterred1 >= 240 Then
    OnError()
    ExitLoop
   Else
    ContinueLoop
   EndIf
  WEnd
  If WinExists("[CLASS:CabinetWClass]","Conexiones de red") Then
   While Not WinActive("[CLASS:CabinetWClass]","Conexiones de red")
    WinActivate("[CLASS:CabinetWClass]","Conexiones de red")
    Sleep(500)
    $counterred2 = $counterred2 + 1
    If $counterred2 >= 240 Then
     OnError()
     ExitLoop
    Else
     ContinueLoop
    EndIf
   WEnd
  $items = ControlListView("Conexiones de red", "", "SysListView321", "GetItemCount")
  $counteritems = 0
   While $items < 1
    WinActivate("[CLASS:CabinetWClass]","Conexiones de red")
    Sleep(500)
    $counteritems = $counteritems + 1
    If $counteritems >= 240 Then
     OnError()
     ExitLoop
    Else
     $items2 = ControlListView("Conexiones de red", "", "SysListView321", "GetItemCount")
     $items = $items2
     ContinueLoop
    EndIf
   WEnd
  EndIf
Sleep(500)
EndFunc
Func Get_ConexExist($conexname)
; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf
    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf
    ; Look for wanted tooltip
    For $ConexExist = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $ConexExist), $conexname) > 0 Then ExitLoop
    Next
    If $ConexExist = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $ConexExist ; Found
    EndIf
EndFunc
Func CheckAndDelConex()
Sleep(50)
While Get_ConexExist($conexname) <> 0
   Sleep(50)
   CheckConexMail()
WEnd
If $delcon = 0 Then
  Sleep(50)
  DelConex()
  EndIf
EndFunc
Func DelConex()
Run("RUNDLL32.EXE SHELL32.DLL,Control_RunDLL ncpa.cpl", "")
ActiveConnectRed()
$incoming = ControlListView("Conexiones de red", "", "SysListView321", "FindItem", "Conexiones entrantes")
$fcounter1 = 0
ControlListView("Conexiones de red", "", "SysListView321", "ViewChange","details")
If $incoming <> -1 Then
ControlListView("Conexiones de red", "", "SysListView321", "Select", $incoming)
Sleep(500)
Send("+{DEL}")
Sleep(500)
While Not ControlCommand('Confirmar eliminación de conexión', '', '[CLASS:Button; INSTANCE:1]', 'IsEnabled', '')
  Sleep(500)
  $fcounter1 = $fcounter1 +1
  If $fcounter1 >= 120 Then
   OnError()
   ExitLoop
  Else
   ContinueLoop
  EndIf
WEnd
ControlSend("Confirmar eliminación de conexión", "", "[CLASS:Button; INSTANCE:1]", "{ENTER}")
EndIf
ActiveConnectRed()
WinClose("Conexiones de red")
$delcon = 1
EndFunc

; FUNCIONA PARA REFRESCAR EL SYSTEM TRAY
Func _RefreshSystemTray($nDelay = 1000)
; Save Opt settings
    Local $oldMatchMode = Opt("WinTitleMatchMode", 4)
    Local $oldChildMode = Opt("WinSearchChildren", 1)
    Local $error = 0
    Do; Pseudo loop
        Local $hWnd = WinGetHandle("classname=TrayNotifyWnd")
        If @error Then
            $error = 1
            ExitLoop
        EndIf
        Local $hControl = ControlGetHandle($hWnd, "", "Button1")
    ; We're on XP and the Hide Inactive Icons button is there, so expand it
        If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then
            ControlClick($hWnd, "", $hControl)
            Sleep($nDelay)
        EndIf
        Local $posStart = MouseGetPos()
        Local $posWin = WinGetPos($hWnd)
        Local $y = $posWin[1]
        While $y < $posWin[3] + $posWin[1]
            Local $x = $posWin[0]
            While $x < $posWin[2] + $posWin[0]
                DllCall("user32.dll", "int", "SetCursorPos", "int", $x, "int", $y)
                If @error Then
                    $error = 2
                    ExitLoop 3; Jump out of While/While/Do
                EndIf
                $x = $x + 8
            WEnd
            $y = $y + 8
        WEnd
        DllCall("user32.dll", "int", "SetCursorPos", "int", $posStart[0], "int", $posStart[1])
    ; We're on XP so we need to hide the inactive icons again.
        If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then
            ControlClick($hWnd, "", $hControl)
        EndIf
    Until 1
; Restore Opt settings
    Opt("WinTitleMatchMode", $oldMatchMode)
    Opt("WinSearchChildren", $oldChildMode)
    SetError($error)
EndFunc; _RefreshSystemTray()

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
Sign in to follow this  

×