如何执行Web浏览器(IE)并让它从输入框访问URL?

时间:2015-01-03 10:36:12

标签: autoit

我是Autoit的新手,我正在尝试创建一个显示输入框和按钮的GUI脚本。

当用户点击按钮时,IE应该启动,输入框中的文本是被访问的地址。

这是我到目前为止所做的:

; Includes the GuiConstants (required for GUI function usage)
#include <GuiConstants.au3>

; Hides tray icon
#NoTrayIcon

Global $inputBox, $downloadsURL

; Change to OnEvent mode
Opt('GUIOnEventMode', 1)

; GUI Creation
GuiCreate("Downloads Script", 400, 200)

; Runs the GUIExit() function if the GUI is closed
GUISetOnEvent($GUI_EVENT_CLOSE, 'GUIExit')
; Instructions
GUICtrlCreateLabel("Please enter Download URL below:", -1, -1)
GUICtrlSetColor(-1,0xFF0000) ; Makes instructions Red
; Input
$downloadsURL = GUICtrlCreateInput("",-1,20)
; Button1
GUICtrlCreateButton("Download File", -1, 60)
GUICtrlSetOnEvent(-1, 'website') ; Runs website() when pressed

Func website()
; Hides the GUI while the function is running
GUISetState(@SW_HIDE)
$inputBox = GUICtrlRead($downloadsURL)

Run("C:\Program Files\Internet Explorer\iexplore.exe", $inputBox)
Exit
EndFunc

; Shows the GUI after the function completes
GUISetState(@SW_SHOW)

; Idles the script in an infinite loop - this MUST be included when using OnEvent mode
While 1
   Sleep(500)
WEnd

; This function makes the script exit when the GUI is closed
Func GUIExit()
Exit
EndFunc

1 个答案:

答案 0 :(得分:2)

您的Run()命令不正确。 Run()的第二个参数不适用于命令行,您可能会想到ShellExecute()。

所以:

Run("C:\Program Files\Internet Explorer\iexplore.exe", $inputBox)

可能会成为:

Run('"C:\Program Files\Internet Explorer\iexplore.exe" ' &  '"' & $inputBox & '"')

注意我将它包装在引号中,因为它/可能包含由程序解释为另一个命令行参数的空格。

另一种方法是使用IE.au3 udf:

#include <IE.au3>
Global $oIE = _IECreate($inputBox)
相关问题