Jump to content

WinExists function does not reconize a window minimized to tray.


 Share

Recommended Posts

Hello all,

I'm doing a script to automatically dial a VPN connection, and after the connetion is estabilished the script will add a static route. Ok my problem is that after the connection is estabilished, it is directlly minimized to tray menu as a network connection status icon. And I only need to add my static route after the connection is estabilished, because i need to use the IP Address acquired in the VPN connection. I'm trying to use the WinExists() function searching for the title of "Status de " (The script will run in a brazilian portuguese version of windows xp) but this function does not finds this window when it is minimized to tray. Here is my code:

;Função que trata as mensagens de erro durante a chamada de uma conexão VPN
Func TrataErro_VPN()
    Sleep(100)
    WinWaitActive("Conectando-se a " & $strConnName)
;MsgBox(0, "Erro de Conexão", "Esperando 1")
    WinWaitNotActive("Conectando-se a " & $strConnName)
;MsgBox(0, "Erro de Conexão", "Esperando 2")
    If WinExists("Erro ao conectar-se a " & $strConnName) = 1 Then
        Sleep(100)
        $strErroVPN = ControlGetText("Erro ao conectar-se a " & $strConnName, "", 1070)
    ;$numTemp = StringInStr($strErroVPN, "678")
    ;MsgBox(0, "String dentro de string", $strErroVPN)
    ;MsgBox(0, "String dentro de string", $numTemp)
        If StringInStr($strErroVPN, "678") = 0 Then
            Sleep(100)
            ControlClick("Erro ao conectar-se a " & $strConnName, "", 2)
            MsgBox(48, "Erro de conexão", "Verifique seu nome de usuário e senha, e tente novamente.")
            Mostra_GUI()
        Else
            Sleep(100)
        ;MsgBox(48, "Erro de conexão", "Sua conexão será rediscada.")
            ControlClick("Erro ao conectar-se a " & $strConnName, "", 1)
            TrataErro_VPN()
        EndIf
        Sleep(2000)     
    ElseIf WinExists("Status de " & $strConnName) = 1 Then
        MsgBox(0, "Conexão estabelecida", "Esperando 1")
        CriaRota()      
        Else
            MsgBox(0, "Conexão nao estabelecida", "Esperando -1")
            Quit()
    EndIf
EndFunc

;Cria uma rota estática utilizando-se do IP obtido ao se conectar a VPN
Func CriaRota()
    MsgBox(0, "Erro de Cria rota", "Esperando 1")
    Dim $strAdminUser = "*****l" 
    Dim $strAdminPass = "*****"
    Dim $strInicioIP = "192.168.150."
    RunAsSet($strAdminUser, @ComputerName, $strAdminPass)   
    Select
        Case StringInStr(@IPAddress1, $strInicioIP) <> 0
            Run(@ComSpec & " /c " & 'route.exe add 172.20.0.0 mask 255.252.0.0 ' & @IPAddress1, "", @SW_HIDE)
        Case StringInStr(@IPAddress2, $strInicioIP) <> 0
            Run(@ComSpec & " /c " & 'route.exe add 172.20.0.0 mask 255.252.0.0 ' & @IPAddress2, "", @SW_HIDE)
        Case StringInStr(@IPAddress3, $strInicioIP) <> 0
            Run(@ComSpec & " /c " & 'route.exe add 172.20.0.0 mask 255.252.0.0 ' & @IPAddress3, "", @SW_HIDE)
        Case StringInStr(@IPAddress4, $strInicioIP) <> 0
            Run(@ComSpec & " /c " & 'route.exe add 172.20.0.0 mask 255.252.0.0 ' & @IPAddress4, "", @SW_HIDE)
    EndSelect
    Quit()
EndFunc

Ps.: If I double click the connection status tray icon to open de status window, and run my script afterwards, then WinExists() finds the window. Also tryed using window handles, but no luck either.

Thanks in advance.

Link to comment
Share on other sites

Moin,

Try this:

; Check if a new notepad window is  minimized
$state = WinGetState("Untitled", "")

; Is the "minimized" value set?
If BitAnd($state, 16) Then
    MsgBox(0, "Example", "Window is  minimized")
EndIf

Greetz

Greenhorn

Thanks for the fast reply! But your tip didn't work either. It's like the windows does not exist until i double click the "tray icon" (the window is not in the taskbar, and it doesnt even have a minimize button). Here (attached) is a picture of the window I want. And its information with the tool windowinfo.
Link to comment
Share on other sites

Moin,

Try this:

; Check if a new notepad window is  minimized
$state = WinGetState("Untitled", "")

; Is the "minimized" value set?
If BitAnd($state, 16) Then
    MsgBox(0, "Example", "Window is  minimized")
EndIf

Greetz

Greenhorn

Thanks for the fast reply! But your tip didn't work either. It's like the windows does not exist until i double click the "tray icon" (the window is not in the taskbar, and it doesnt even have a minimize button). Here (attached) is a picture of the window I want. And its information with the tool windowinfo.

post-31599-1201271439_thumb.jpg

post-31599-1201271612_thumb.jpg

Link to comment
Share on other sites

Ahhh, now I know what you mean. :D:P

It is not a window of an application, it's the Network connection.

Do you have a shortcut to the Network connection, maybe on the Desktop or in the Quick Launch Bar ?

If it is the case, then just call the shortcut again with ShellExecute(). That should work to reactivate the window, my friend.

Greetz

Link to comment
Share on other sites

Ahhh, now I know what you mean. :D:P

It is not a window of an application, it's the Network connection.

Do you have a shortcut to the Network connection, maybe on the Desktop or in the Quick Launch Bar ?

If it is the case, then just call the shortcut again with ShellExecute(). That should work to reactivate the window, my friend.

Greetz

The only icon avaiable is the icon created by windows in "Network Connections" page (right click my network places and then properties). But I see what you mean... After I'm connected to the VPN, if I click the VPN icon in Network Connections it activates the Status window (and thats the window I want!). Ok this solution its not the best way (there shoul be a way to check if a VPN is connect or not), but it should work. I will try it now and post the results here after. Thanks a lot!

Link to comment
Share on other sites

Maybe you can get the same result by using a DLLCall, but I don't know which one or how to investigate it ...

I mean it like this one:

; Schnellstartleiste anzeigen.
Run('rundll32.exe shell32.dll,Options_RunDLL 1')
WinWait('Eigenschaften von Taskleiste und Startmenü', 'Taskleiste')
WinSetState('Eigenschaften von Taskleiste und Startmenü', 'Taskleiste', @SW_HIDE)
ControlClick('Eigenschaften von Taskleiste und Startmenü', 'Taskleiste', 'Button5')
Sleep(150)
;ControlClick('Eigenschaften von Taskleiste und Startmenü', 'Taskleiste', 'Button12')
Sleep(150)
;ControlClick('Eigenschaften von Taskleiste und Startmenü', 'Taskleiste', 'Button11')
Exit

If you get an information about this, please let me know, cause I'm also interested in this ...

Maybe start a new topic/thread for searching that call ...

Greetz

Edit: Sorry, forgot this is for a german Windows ...

Eigenschaften von Taskleiste und Startmenü = Properties of Taskbar and Start Menu

Edited by Greenhorn
Link to comment
Share on other sites

Maybe you can get the same result by using a DLLCall, but I don't know which one or how to investigate it ...

I mean it like this one:

; Schnellstartleiste anzeigen.
Run('rundll32.exe shell32.dll,Options_RunDLL 1')
WinWait('Eigenschaften von Taskleiste und Startmenü', 'Taskleiste')
WinSetState('Eigenschaften von Taskleiste und Startmenü', 'Taskleiste', @SW_HIDE)
ControlClick('Eigenschaften von Taskleiste und Startmenü', 'Taskleiste', 'Button5')
Sleep(150)
;ControlClick('Eigenschaften von Taskleiste und Startmenü', 'Taskleiste', 'Button12')
Sleep(150)
;ControlClick('Eigenschaften von Taskleiste und Startmenü', 'Taskleiste', 'Button11')
Exit

If you get an information about this, please let me know, cause I'm also interested in this ...

Maybe start a new topic/thread for searching that call ...

Greetz

Edit: Sorry, forgot this is for a german Windows ...

Eigenschaften von Taskleiste und Startmenü = Properties of Taskbar and Start Menu

Hello Friend! Just to update you. I found a solution for my problem! I used the function StdoutRead() and the call to the command "rasdial.exe", this returns if you have a Dial-Up or VPN connection running! Here is the code i used:

$strGetStdOut = Run("rasdial.exe", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
        $strIsConnected = StdoutRead($strGetStdOut)
        If StringInStr($strIsConnected, "Conectado a") = 1 Then         
            CriaRota()
        EndIf

Conectado a = Connected to

Ps.: Need #include <Constants.au3> to work!

Thanks for your help!!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...