VBS Command Line

From iMacros
Jump to: navigation, search

This example demonstrates how pass values to a VBS script with WScript.Arguments from the command line. You can use this, for example, to start a VBS file from batch files or the Windows task scheduler.

 If WScript.Arguments.Count = 3 Then
  Macro1 = WScript.Arguments.Item(0)
  Macro2 = WScript.Arguments.Item(1)
  Macro3 = WScript.Arguments.Item(2)
 Else
  Wscript.Echo "Usage: MyScript.vbs Macro1 Macro2 Macro3"
  Wscript.Quit
 End If

Example: Start Internet Explorer from the command line and run the specified macro. We assume that the VBS file is named "start-ie.vbs".

VBS File:

 If WScript.Arguments.Count = 1 Then
  Macro1 = WScript.Arguments.Item(0)
 Else
  Wscript.Echo "Usage: start-ie.vbs Macro1"
  Wscript.Quit
 End If
   
set iim1= CreateObject ("imacros")
 
'Start Internet Explorer
iret = iim1.iimInit ("-ie")
 
'Run the macro
iret = iim1.iimPlay(macro1)

'Close IE again
iret = iim1.iimExit(1)
WScript.Quit(0)

Command Line:

 start-ie.vbs mymacro