connect-to-ie.vbs
Jump to navigation
Jump to search
This example script connects to an already open instance of Internet Explorer. If it can not find one it starts Internet Explorer. In both cases, the iMacros Add-on has to be active (when the last closed Internet Explorer window had an open iMacros sidebar).
It calls the macros Wsh-Start.iim, Wsh-Luch.iim and Wsh-Submit-Button.iim.
Technically this script is exactly the same as a script that uses the iMacros Browser, but it invokes Internet Explorer with iimOpen("-ie").
Visual Basic Script:
' iMacros Connect-To-IE Script ' (c) 2008-2015 iOpus/Ipswitch Inc. Option Explicit Dim iim1, iret '**** ' find current folder Dim myname, mypath myname = WScript.ScriptFullName mypath = Left(myname, InstrRev(myname, "\")) Dim message message = "This example script connects to an already open instance of Internet Explorer with an active (open) iMacros Add-On." message = message + " If it can not find one, it starts Internet Explorer." MsgBox(message) set iim1= CreateObject ("imacros") iret = iim1.iimOpen("-IE", false) if iret < 0 then MsgBox ("For this example to work you must make sure that the iMacros Add-On is **open** (visible) before you close Internet Explorer. Then the iMacros Add-On is started automatically whenever IE starts and the Scripting Interface can connect to it.") iret = iim1.iimDisplay("Start demo") 'Run first macro iret = iim1.iimPlay(mypath & "Macros\Wsh-Start.iim", 30) if iret < 0 Then MsgBox "Error code: "+cstr(iret) + VbCrLf + "Error Text: "+iim1.iimGetErrorText() End If 'Run second macro iret = iim1.iimPlay(mypath & "Macros\Wsh-Lunch.iim", 30) if iret < 0 Then MsgBox "Error code: "+cstr(iret) + VbCrLf + "Error Text: "+iim1.iimGetErrorText() End If 'Run third macro iret = iim1.iimPlay(mypath & "Macros\Wsh-Submit-Btton.iim", 30) if iret < 0 Then MsgBox "Error code: "+cstr(iret) + VbCrLf + "Error Text: "+iim1.iimGetErrorText() End If iret = iim1.iimDisplay("Script completed.") MsgBox "Close Internet Explorer" iim1.iimClose(30) WScript.Quit(iret)
Wsh-Start.iim macro
TAB T=1 TAB CLOSEALLOTHERS URL GOTO=http://demo.imacros.net/Automate/ TAG POS=1 TYPE=A ATTR=TXT:*Testform1* TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=NAME:name CONTENT=Tom<SP>Tester TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=NAME:food CONTENT=$Pizza TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=NAME:drink CONTENT=$Coke TAG POS=1 TYPE=INPUT:RADIO FORM=ID:demo ATTR=ID:small&&VALUE:small CONTENT=YES TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=ID:dessert CONTENT=%ice<SP>cream:%apple<SP>pie TAG POS=1 TYPE=INPUT:RADIO FORM=ID:demo ATTR=NAME:Customer CONTENT=YES TAG POS=1 TYPE=INPUT:RADIO FORM=ID:demo ATTR=NAME:Customer&&VALUE:Not_yet CONTENT=YES
Wsh-Lunch.iim macro
TAG POS=1 TYPE=TEXTAREA FORM=ID:demo ATTR=NAME:Remarks CONTENT=Lunch
Wsh-Submit-Button.iim macro
TAB T=1 TAB CLOSEALLOTHERS TAG POS=1 TYPE=BUTTON:SUBMIT FORM=ID:demo ATTR=TXT:Click<SP>to<SP>order<SP>now WAIT SECONDS=3 URL GOTO=http://demo.imacros.net/Automate/OK