set-user-agent.vbs

From iMacros
Jump to: navigation, search

Please, notice that this example just aplies to iMacros 6 and below. The command line switch in deprecated in iMacros 7. In iMacros 7 and iMacros for Firefox please use the SET !USERAGENT new<SP>value command instead.

When initializing an iMacros instance, you can select what user agent the browser should use in iimInit.

Option Explicit
Dim iim1, iret
Dim rn, i, keyword

iret = MsgBox ("This example script shows how to set the user agent for the iMacros Browser."+VbCrLf+VbCrLf+"For this demo we simulate the user agent of a Nokia mobile phone device and test the response of the Yahoo Home Page.", 0, "iMacros VBS Script")

set iim1= CreateObject ("imacros")
iret = iim1.iimInit ("-useragent ""Nokia6230/2.0+(04.43)+Profile/MIDP-2.0+Configuration/CLDC-1.1+UP.Link/6.3.0.0.0"" ")

Dim MyMacroCode
MyMacroCode = "CODE:"
MyMacroCode = MyMacroCode+"URL GOTO=http://demo.imacros.net/UserAgent.aspx" + vbNewLine
MyMacroCode = MyMacroCode+"WAIT SECONDS=3" + vbNewLine

iret = iim1.iimDisplay("Display user agent on test page")
  
'Run the first macro
iret = iim1.iimPlay(MyMacroCode)

if iret < 0 Then
   MsgBox  "Error in Macro#1: "+ iim1.iimGetLastError()
End If


MyMacroCode = "CODE:"
MyMacroCode = MyMacroCode+"URL GOTO=http://www.yahoo.com" + vbNewLine
MyMacroCode = MyMacroCode+"WAIT SECONDS=3" + vbNewLine

iret = iim1.iimDisplay("Test Yahoo behavior with Nokia user agent")
   
'Run the first macro
iret = iim1.iimPlay(MyMacroCode)

if iret < 0 Then
   MsgBox  "Error in Macro#1: "+ iim1.iimGetLastError()
End If



iret = iim1.iimDisplay("Script completed.")

'Ask user:
iret = MsgBox ("The user agent demo is completed. Do you want to close the iMacros Browser now?",1,"iMacros VBS Script")
if iret = 1 then iret = iim1.iimExit

WScript.Quit(0)