Jump to content
Sign in to follow this  
icadea

vnc script hangs after an error

Recommended Posts

icadea

hi all,

Shown below is a working script that i made. The code and the vncviewer.exe are put into the same folder.

The only problem with the script is if I were to use press test1 button at the test1 computer, i have an vncviewer error saying loop back not enabled...) After that if i were to click test2 button from the same computer the script does not work.

I have to exit, start the script and press test2 button for it to work. Why is this error occurs? I have tried using if error Return/Exit but it still hangs the script.

Please advise. thanks

#include <GUIConstants.au3>

$form1 = GUICreate("form1", 514, 106, 502, 605)
GUISetBkColor(0xC0C0C0)
$test1 = GUICtrlCreateButton("test1", 8, 72, 49, 25, 0)
GUICtrlSetFont(-1, 8, 800, 0, "Verdana")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x008000)
$test2 = GUICtrlCreateButton("test2", 64, 72, 49, 25, 0)
GUICtrlSetFont(-1, 8, 800, 0, "Verdana")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x008000)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $test1
            test1()
        Case $test2
            test2()


    EndSwitch
WEnd

Func test1()
    ShellExecute("vncviewer.exe", "", @ScriptDir)
    WinWaitActive("VNC Viewer : Connection Details")
    ControlSend("VNC Viewer : Connection Details", "", 1001, "192.168.1.4")
    Sleep(100)
    ControlClick("VNC Viewer : Connection Details", "OK", 1)
    Sleep(100)
    WinWaitActive("VNC Viewer : Authentication [No Encryption]")
    ControlSend("VNC Viewer : Authentication [No Encryption]", "", 1000, "admin1")
    Sleep(100)
    ControlClick("VNC Viewer : Authentication [No Encryption]", "OK", 1)
    Sleep(100)
EndFunc  ;==>test1

Func test2()
    ShellExecute("vncviewer.exe", "", @ScriptDir)
    WinWaitActive("VNC Viewer : Connection Details")
    ControlSend("VNC Viewer : Connection Details", "", 1001, "192.168.1.5")
    Sleep(100)
    ControlClick("VNC Viewer : Connection Details", "OK", 1)
    Sleep(100)
    WinWaitActive("VNC Viewer : Authentication [No Encryption]")
    ControlSend("VNC Viewer : Authentication [No Encryption]", "", 1000, "admin1")
    Sleep(100)
    ControlClick("VNC Viewer : Authentication [No Encryption]", "OK", 1)
    Sleep(100)
EndFunc  ;==>test2

Share this post


Link to post
Share on other sites
therks

It's probably a problem with one of the WinWait()'s. Try adding the timeout parameter to them.

Something like

Func test1()
    ShellExecute("vncviewer.exe", "", @ScriptDir)
    If WinWaitActive("VNC Viewer : Connection Details", "", 5) Then
        ControlSend("[LAST]", "", 1001, "192.168.1.4")
        Sleep(100)
        ControlClick("[LAST]", "OK", 1)
        Sleep(100)
        If WinWaitActive("VNC Viewer : Authentication [No Encryption]", "", 5) Then
            ControlSend("[LAST]", "", 1000, "admin1")
            Sleep(100)
            ControlClick("[LAST]", "OK", 1)
            Sleep(100)
        Else
            MsgBox(16, "Error", "Could not find window 'VNC Viewer : Authentication [No Encryption]' in 5 seconds")
        EndIf
    Else
        MsgBox(16, "Error", "Could not find window 'VNC Viewer : Connection Details' in 5 seconds")
    EndIf
EndFunc  ;==>test1

Share this post


Link to post
Share on other sites
icadea

thanks for the help :) i'll check them out

Share this post


Link to post
Share on other sites
icadea

thank for the help Saunders, it works fine.

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  

×