kevin
kevin

Reputation: 49

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

I'm new to Autoit, and I am trying to create a GUI script that displays an input box and button.

When the user clicks the button, IE is supposed to launch, with the text from the inputbox being the address being accessed.

This is what I have so far:

; 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

Upvotes: 0

Views: 4576

Answers (1)

SmOke_N
SmOke_N

Reputation: 136

Your Run() command is incorrect. The second parameter of Run() is not for command lines, you may be thinking of ShellExecute().

So:

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

Might become:

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

Note I wrapped it in quotes because it does/may contain spaces which is interpreted by the program as another command line parameter.

Another way is using the IE.au3 udf:

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

Upvotes: 2

Related Questions