Jump to content
Sign in to follow this  
Guest Frustrated_Worker

help appreciated - script is not working

Recommended Posts

Guest Frustrated_Worker

Hi everybody.

I am a newbie seeking for some help.

I´m writing a little script to automate the installation of a program.

But I`m totally frustrated, because I don`t get the right way to use the

winhandles in combination with the GUIGetMSg() poll function.

(Reading the help and some forum topics doesn`t give me a clue)

There must be something wrong with my script. I think it`s only a problem of understanding. But, please can someone take a look at the script and tell me why the windows I am switching to did not have the focus, so they doesn`t react on my mouse-clicks.

I give you the whole script (ca. 190 lines), because I don`t really know which parts are the troublesome.

help is greatly appreciated,

Thanks in advance,

Nick

Script: (text is in german)

; AutoIt Version: 3.1.0
;Installation GUI of OpenVPN Client
; Script Start - Add your code below here

#include <GUIConstants.au3>
AutoItSetOption("TrayIconDebug", 1)
;*************************Hauptfenster*******************************

Global $parent, $child1, $child2, $msg, $msg1, $msg2, $msg3, $but1, $but2, $but3, $ibut
Opt("GUIOnEventMode", 1)
Opt("GUICoordMode",1)
Opt("GUIResizeMode",1)

Do
    $parent = GUICreate("OpenVPN Client Install Assistant", 450, 225) 
    GUISetOnEvent($GUI_EVENT_CLOSE, "END")
    GUISetFont(10,600)
    GUICtrlCreateLabel("Bitte treffen Sie eine Auswahl:", 20, 20, 300, 20)
    GUISetFont(9,400)
    GUICtrlCreateLabel("(Hier klicken, um das Installationsmenü aufzurufen.)", 20, 70, 300, 20)
    GUISetFont(9,600)
    $gui = GUICtrlCreateButton ("Client installieren", 285, 65, 135)
    GUISetFont(9,400)
    GUICtrlCreateLabel("(Hier klicken, um das Kopiermenü aufzurufen.)", 20, 120, 300, 20)
    GUISetFont(9,600)
    $key = GUICtrlCreateButton ("Schlüssel kopieren", 285, 115, 135)
; Entscheidung für Funktion        
    GUICtrlSetOnEvent($key, "KEY")
    GUICtrlSetOnEvent($gui, "GUI")
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
    Wend
Until $msg = $GUI_EVENT_CLOSE
Exit 

;***************Fenster Kopiermenü********************************
Func KEY()
Opt("GUIOnEventMode", 0)    
$child1 = GUICreate("Menü: Schlüssel kopieren", 450, 225) 
GUISetFont(10,600)
GUICtrlCreateLabel("Bitte Knopf drücken, um Schlüssel zu kopieren:", 20, 20, 400, 20)
GUISetFont(9,400)
GUICtrlCreateLabel("(Hinweis: Ein bereits vorhandener Schlüssel" & @CRLF & "wird _
ohne Nachfrage überschrieben.)", 20, 60, 300 ,30)
GUISetFont(9,600)
$but3 = GUICtrlCreateButton("Kopieren", 275, 60, 80)
GUISetState(@SW_SHOW, $child1)
GUISetState(@SW_HIDE, $parent)
GUISetState(@SW_HIDE, $child2)
While 1     
    $msg1 = GUIGetMsg()
    Select
        Case $msg1 = $but3
; eigentlicher Kopiervorgang
            If FileExists ("C:\Programme\OpenVPN\bin\openvpn-gui.exe") Then 
                FileChangeDir("sdata")
                FileCopy ("*.*", "c:\DOWN\")
                GUISwitch($child1)
                Sleep (2000)
                GUISetFont(9,400)
                GUICtrlCreateLabel("Die Schlüsseldateien sind erfolgreich" & @CRLF & "auf die Festplatte _kopiert worden." & @CRLF & @CRLF &"Das Programm wird jetzt beendet!",20, 110, 400, 70)
                GUICtrlSetColor(-1, 0x0080FF)
                Sleep (3000)
                call ("END")
            Else
;Nach Abbruch Aufruf von Installationsmenü             
                GUISwitch($child1)
                GUISetFont(9,400)
                GUICtrlCreateLabel("Der OpenVPN Client für Windows muß vorher _installiert werden.",20, 120, 400, 30)
                GUICtrlSetColor(-1, 0xff0000)
                GUICtrlCreateLabel("Es wird zum Installationsmenü gewechselt!",20, 150, 400, 30)
                GUICtrlSetColor(-1, 0xff0080ff)
                Sleep (2000)
                GUISetState(@SW_HIDE, $parent)
                GUISetState(@SW_HIDE, $child1)  
                GUISetState(@SW_SHOW, $child2)
                GUISwitch($child2)
                call ("GUI")
            EndIf
        Case $msg1 = $GUI_EVENT_CLOSE
        call ("END")
    EndSelect
Wend
EndFunc

; **********************Fenster Installationsmenü*******************
Func GUI()
Opt("GUICoordMode",1)
Opt("GUIOnEventMode", 0)
Opt("GUIResizeMode",0)
$child2 = GUICreate("Menü: OpenVPN Client installieren", 450, 225,) 
GUISetFont(10,600)
GUICtrlCreateLabel("Es wird überprüft, ob der OpenVPN Client" & @CRLF & "für Windows bereits _
installiert ist." & @CRLF & "Bitte warten...", 20, 20, 400, 50)
GUISetState(@SW_SHOW, $child2)
GUISetState(@SW_HIDE, $parent)
;GUISetState(@SW_HIDE, $child1)
Sleep (2000)
If FileExists ("C:\Programme\OpenVPN\bin\openvpn-gui.exe") Then
    GUISwitch($child2)
    Opt("GUIOnEventMode", 0)
    GUISetFont(9,400)
    GUICtrlCreateLabel("Das Programm ist bereits installiert. Soll es deinstalliert werden?", 20, 80 ,400, 50)
    GUICtrlSetColor(-1,0xff0000)
    GUISetFont(9,400)
    GUICtrlCreateLabel("(Hier klicken, um das Programm zu deinstallieren)", 20, 110 ,400, 50)
    GUISetFont(9,600)
    $but1 = GUICtrlCreateButton("JA", 315, 105, 50)
    GUISetFont(9,400)
    GUICtrlCreateLabel("(Hier klicken, um zum Kopiermenü zu wechseln.)", 20, 140 ,400, 50)
    GUISetFont(9,600)
    $but2 = GUICtrlCreateButton("NEIN", 315, 135, 50)
    ControlGetFocus("Menü: OpenVPN Client installieren")
;GUISetState(@SW_SHOW, $child2)
;GUISetState(@SW_HIDE, $child1)
;GUISetState(@SW_HIDE, $parent)
;GUISwitch($child2)
    While 1
        $msg3 = GUIGetMsg()
        Select
            Case $msg3 = $but1
; Deinstallation wenn schon vorhanden
                RunWait ("C:\Programme\OpenVPN\Uninstall.exe")
                GUISwitch($child2)
                GUISetFont(9,400)
                GUICtrlCreateLabel("Openvpn für Windows ist erfolgreich deinstalliert _    worden." & @CRLF & "Das Programm wird beendet!", 20, 170)
                GUICtrlSetColor(-1, 0x0080FF)
                GUISetState(@SW_SHOW)
                Sleep (3000)
                call ("END")
            Case $msg3 = $but2
; Bei Abbruch Aufruf des Kopiermenüs           
                GUISwitch($child2)
                GUISetFont(9,400)
                GUICtrlCreateLabel("Es wird zum Kopiermenü gewechselt!", 20, 170 ,400, 50)
                GUICtrlSetColor(-1,0x0080ff)
                GUISetState(@SW_SHOW)
                Sleep (3000)
                call ("KEY")
            Case $msg3 = $GUI_EVENT_CLOSE
                call ("END")
        EndSelect
    Wend
Else
    GUISwitch($child2)
    Opt("GUIOnEventMode", 0)
    GUISetFont(9,400)
    GUICtrlCreateLabel("Das Programm ist nicht installiert.", 20, 80 ,400, 50)
    GUICtrlSetColor(-1,0x008000)
    GUISetFont(9,400)
    GUICtrlCreateLabel("(Hier klicken, um das Programm zu installieren.)", 20, 110 ,275, 50)
    GUISetFont(9,600)
    $ibut = GUICtrlCreateButton("Installieren", 300, 105, 95)
    GUISetState(@SW_SHOW, $child2)
    GUISetState(@SW_HIDE, $parent)
    GUISetState(@SW_HIDE, $child1)
    While 1 
        $msg2 = GUIGetMsg()
        Select
        Case $msg2 = $ibut 
; Installation der GUI anschließend Aufruf des Kopiermenüs            
            GUISetState(@SW_SHOW, $child2)
            FileChangeDir("idata")
            RunWait("openvpn20rc16.exe")
            GUISetFont(9,400)       
            GUICtrlCreateLabel("Openvpn ist erfolgreich installiert worden." & @CRLF & "Das _Kopiermenü wird aufgerufen!", 20, 140, 400, 50)
            GUICtrlSetColor(-1, 0x0080FF)
            Sleep (5000)
            GUISetState(@SW_HIDE, $child2)
            GUISwitch($child1)
            call ("KEY")
        Case $msg2 = $GUI_EVENT_CLOSE
            call ("END")
        EndSelect       
    Wend
EndIf
EndFunc

Func END()
;MsgBox(4096,"", "Bitte Bestätigen!")
Exit
EndFunc
Edited by Larry

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  

×