Jump to content

Conditional GUI Within Function


 Share

Recommended Posts

It still loads the gui even when i dont call the function. Here's my code

#include <string.au3>
#include <GUIConstants.au3>
Global $encpass = 0
Global $password = 0
Global $encrypt = ''
Func _createpassword()
    GUICreate('Password For VPN',310,25)
    GUICtrlCreateLabel('CSMCC Password',0,0,50,25)
    Opt('GUICoordMode',2)
    $passin = GUICtrlCreateInput('',0,-1,200,25,$ES_LEFT+$ES_AUTOHSCROLL+$ES_PASSWORD)
    $OK = GUICtrlCreateButton('OK',0,-1,60,25)
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $OK
            $password = GUICtrlRead($passin)
            MsgBox(0,'Password',$password)
            $encpass = _StringEncrypt(1,$password,$encrypt)
            IniWrite('password.ini','VPN Password','password',$encpass)
            ExitLoop
        EndSelect
    WEnd
    GUISetState(@SW_HIDE)
EndFunc
If FileExists('password.ini') Then
    $encpass = IniRead('password.ini','VPN Password','password',0)
    If $encpass = 0 Then
;~      _createpassword()
    Else
        $password = _StringEncrypt(0,$encpass,$encrypt)
    EndIf
Else
;~  _createpassword()
EndIf   
While 1
    WinWaitActive('VPN Client')
    Send('^o')
    If WinWait('VPN Client  |  User Authentication for "CSM"','',10000) = 1 Then
        ControlSend('VPN Client  |  User Authentication for "CSM"','password','QWidget4',$password)
        ControlClick('VPN Client  |  User Authentication for "CSM"','unnamed','QWidget2')
;~  Else
;~      Sleep(10000)
;~      WinSetState('VPN Client','',@SW_HIDE)
    EndIf
WEnd
Link to comment
Share on other sites

Well, I ran your code with all the function calls commented out, and the GUI didn't show up. So, it has to do with the rest of your code calling the function.

I think you might want to look at this part especially:

If FileExists('password.ini') Then
    $encpass = IniRead('password.ini','VPN Password','password',0)
    If $encpass = 0 Then
;~       _createpassword()
    Else
        $password = _StringEncrypt(0,$encpass,$encrypt)
    EndIf
Else
;~   _createpassword()
EndIf

I suspect your iniread isn't working out correctly (or it doesn't exist).

Link to comment
Share on other sites

Modified the script so it works. The INIRead getting $encpass was returning a hex string (encrypted) when it worked, but then that made it equal to 0. So I changed it to default to "" and check if $encpass = "".

Also, you need $encrypt to equal something, a blank string didn't work for me....

#include <string.au3>
#include <GUIConstants.au3>
Global $encpass = 0
Global $password = 0
Global $encrypt = 'a'
Func _createpassword()
    GUICreate('Password For VPN',310,25)
    GUICtrlCreateLabel('CSMCC Password',0,0,50,25)
    Opt('GUICoordMode',2)
    $passin = GUICtrlCreateInput('',0,-1,200,25,$ES_LEFT+$ES_AUTOHSCROLL+$ES_PASSWORD)
    $OK = GUICtrlCreateButton('OK',0,-1,60,25)
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $OK
            $password = GUICtrlRead($passin)
            $encpass = _StringEncrypt(1,$password,$encrypt)
            ExitLoop
        EndSelect
    WEnd
    GUISetState(@SW_HIDE)
EndFunc
If FileExists('password.ini') Then
    $encpass = IniRead('password.ini','VPN Password','password',"")
    If $encpass = "" Then
        _createpassword()
    Else
        $password = _StringEncrypt(0,$encpass,$encrypt)
    EndIf
Else
    _createpassword()
EndIf   
While 1
    WinWaitActive('VPN Client')
    Send('^o')
    If WinWait('VPN Client  |  User Authentication for "CSM"','',10000) = 1 Then
        ControlSend('VPN Client  |  User Authentication for "CSM"','password','QWidget4',$password)
        ControlClick('VPN Client  |  User Authentication for "CSM"','unnamed','QWidget2')
;~   Else
;~       Sleep(10000)
;~       WinSetState('VPN Client','',@SW_HIDE)
    EndIf
WEnd
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...