我需要帮助检查脚本

时间:2016-09-01 17:28:26

标签: autoit

我在自动中遇到一个简单的登录Gui的问题,我真的不知道为什么它不会打印用户名并传递给文本文件

这里的守则:

$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)

我试图使用不同的代码行,但我不能找到问题。 先谢谢

1 个答案:

答案 0 :(得分: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)