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

How do I execute a web browser (IE) and have it access a URL from an input box?

我是 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

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

所以:

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

可能会变成:

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

注意我用引号括起来是因为它 does/may 包含空格,程序将其解释为另一个命令行参数。

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

#include <IE.au3>
Global $oIE = _IECreate($inputBox)