Autoit 如何执行web浏览器(IE)并使其从输入框访问URL?

Autoit 如何执行web浏览器(IE)并使其从输入框访问URL?,autoit,Autoit,我是Autoit的新手,我正在尝试创建一个GUI脚本来显示输入框和按钮 当用户单击按钮时,IE应该启动,输入框中的文本就是访问的地址 这就是我到目前为止所做的: ; Includes the GuiConstants (required for GUI function usage) #include <GuiConstants.au3> ; Hides tray icon #NoTrayIcon Global $inputBox, $downloadsURL ; Change

我是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
;包括GUI常量(GUI函数使用所需)
#包括
; 隐藏托盘图标
#诺特雷肯
全局$inputBox,$downloadsURL
; 更改为OneEvent模式
Opt('GUIOnEventMode',1)
; 图形用户界面创建
GuiCreate(“下载脚本”,400200)
; 如果GUI已关闭,则运行GUIExit()函数
GUISetOnEvent($GUI\u事件\u关闭,'GUIExit')
; 说明书
GUICtrlCreateLabel(“请在下面输入下载URL:”,-1,-1)
GUICtrlSetColor(-1,0xFF0000);使指示变红
; 输入
$downloadsURL=GUICtrlCreateInput(“,-1,20)
; 按钮1
GUICtrlCreateButton(“下载文件”、-1、60)
GUICtrlSetOnEvent(-1,“网站”);按下时运行网站()
Func网站()
; 在函数运行时隐藏GUI
GUISetState(@SW_HIDE)
$inputBox=GUICtrlRead($downloadsURL)
运行(“C:\Program Files\Internet Explorer\iexplore.exe”,$inputBox)
出口
EndFunc
; 显示函数完成后的GUI
GuiseState(@SW_SHOW)
; 在无限循环中空闲脚本-在使用OneEvent模式时必须包括这一点
而1
睡眠(500)
温德
; 此函数用于在关闭GUI时退出脚本
Func GUIExit()
出口
EndFunc
您的Run()命令不正确。Run()的第二个参数不适用于命令行,您可能会想到ShellExecute()

因此:

可能成为:

Run('"C:\Program Files\Internet Explorer\iexplore.exe" ' &  '"' & $inputBox & '"')
注意:我用引号将其括起来,因为它确实/可能包含空格,程序将其解释为另一个命令行参数

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

#include <IE.au3>
Global $oIE = _IECreate($inputBox)
#包括
全局$oIE=\u IECreate($inputBox)

感谢您提供这两种类型的答案。我会选择第二个选项。非常感谢。
#include <IE.au3>
Global $oIE = _IECreate($inputBox)