2016-09-01 164 views
1

我有一個問題用一個簡單的登錄桂在AutoIt的,我真的不能找出爲什麼它不會打印的用戶名和傳遞到一個文本文件我需要幫助檢查腳本

下面的代碼:

$gui = GuiCreate("Authenticate",120,170) 

GUICtrlCreateLabel("Username:",10,10,50,20) 
$username = GUICtrlCreateInput("",10,35,100,20) 

GUICtrlCreateLabel("Password:",10,70,50,20) 
$password = GUICtrlCreateInput("",10,95,100,20,0x0020) 

$go = GuiCtrlCreateButton("OK",10,130,50,25) 
$cancel = GuiCtrlCreateButton("Cancel",60,130,50,25) 

GUISetState() 
Do 
$msg = GUIGetMsg() 

If $msg = $go Then 

    FileWrite(@ScriptDir & '\userout.txt', $username) 
    FileWrite(@ScriptDir & '\passout.txt', $password) 
    Run("confirm.bat", "", @SW_HIDE) 

EndIf 

If $msg = $cancel Then 
Exit 
EndIf 

Until GUIGetMsg() = $cancel 
GuiDelete($gui) 

我試過使用不同的代碼行,但我無法找到問題。 預先感謝

回答

0

您已忘記讀出控件。在你的腳本中,你只能得到control-id的值。

$gui = GuiCreate("Authenticate",120,170) 

GUICtrlCreateLabel("Username:",10,10,50,20) 
$username = GUICtrlCreateInput("",10,35,100,20) 

GUICtrlCreateLabel("Password:",10,70,50,20) 
$password = GUICtrlCreateInput("",10,95,100,20,0x0020) 

$go = GuiCtrlCreateButton("OK",10,130,50,25) 
$cancel = GuiCtrlCreateButton("Cancel",60,130,50,25) 

GUISetState() 
Do 
$msg = GUIGetMsg() 

If $msg = $go Then 

    ; FileWrite(@ScriptDir & '\userout.txt', $username) ; wrong 
    FileWrite(@ScriptDir & '\userout.txt', GUICtrlRead($username)) ; correct 
    ; FileWrite(@ScriptDir & '\passout.txt', $password) ; wrong 
    FileWrite(@ScriptDir & '\passout.txt', GUICtrlRead($password)) ; correct 
    Run("confirm.bat", "", @SW_HIDE) 

EndIf 

If $msg = $cancel Then 
Exit 
EndIf 

Until GUIGetMsg() = $cancel 
GuiDelete($gui)