Imacros scripting interface - how to recreate in UIV?

The iMacros Enterprise Edition automatically installs theScripting Interface. You can control iMacros with any Windows programming language that supports the use of COM objects.

Almost all Windows programming languages support this technology, including the free Windows Scripting Host, Visual Basic 6, Visual Basic .NET, C#, Java, Perl, Python, C++, ASP, PHP, ASP .NET. On the iMacros homepage many examples for different programming languages can be found.

=> I know there is a command line API in UIV, but I am a bit lost on how to get started.

For example, how to convert the VBS script shown here:

'initialize Scripting Interface
Set iim1 = CreateObject ("IMacros")
i = iim1.iimOpen() 

' setting variables
i = iim1.iimSet("name", "Tom Tester")
i = iim1.iimSet("age", "34")

' displaying message
i = iim1.iimDisplay("This is a test")

' play macro
i = iim1.iimPlay("myfirstmacro")

' check success
If i > 0 Then
  s = "Everything OK"
Else
  s = iim1.iimGetErrorText()
End If
MsgBox s

' exit iMacros
i = iim1.iimClose()

Nice question. You can achieve exactly the same what the iMacros Scripting interface does with the UIV RPA command line.

Sample code for VBS, Powershell, Python,… etc can be found here:

In the following I explain how to replace each imacros scripting interface command by the corresponding UIV code. (VBS example code, same works also in Python etc).

iimOpen()

This is done by starting the browser (Chrome, Edge, Firefox) directly using a special URL:

iimSet()

In UIV RPA you can use the special command line parameters &cmd_var1, &cmd_var2,… to send values from the script to the macro/browser extension:

In the macro you can retrieve these values in the ${!cmd_var1}, ${!cmd_var2},… variables.

iimDisplay

You can instruct the UIV extension itself to display a popup with the ECHO command:

iMacros Alternative: iimDisplay

iimPlay

We provide sample code for a “PlayAndWait” function in many programming languages. This can be used whereever you use(d) iimPlay in your script.

You can start many macros directly after another by calling “PlayAndWait” and then again “PlayAndWait”.

iimGetErrorText

The “PlayAndWait” function also retrieves the error message/success message from UIV. See the image above (code marked in blue).

iimGetExtract

In iMacros logic, this command returns the content of the !EXTRACT variable, which are the web-scraped values. Ui.Vision has no such variable, but there are other ways to get the content of macro variables in return after a macro is played:

In Ui.Vision you can retrieve the web-scraping results by saving them as CSV file, and then reading the CSV file from within your script.

Alternatively you can transfer information via the clipboard by storing it in the !Clipboard variable.

Also keep in mind:

Unlike iMacros, Ui.Vision supports flow control directly inside the macro! So in many cases you no longer have to transfer information back into your calling script to e. g. make an IF/THEN decision there. Instead you can create conditional decisions and loops over extracted data directly inside the Ui.Vision macros. This simplifies the script/macro creation and makes debugging easier.

iimClose

With UI Vision (UIV) you close the app by telling it via command to close after the macro is done. If you add &closeRPA=1 the UIV user interface is closed, and if you add &closeBrowser=1 then the browser is closed, too.

Note that all of this works on Windows, Mac and Linux. UIV is a cross-platform automation solution.

Here the the VBS script in action:

https://www.screencast.com/t/uLWHTBm13E

PS: For more information see our iMacros alternatives help page

1 Like

That’s great to know, but where to put them in the .vbs?
I’ve added the PlayandWait function and tried numerous configurations to get the .json script to run, but nothing doing. It will not play, remotely I should add. I can get the vbs to run by double clicking it and it runs the json, without reading the varDictionary parameters. But we need it to be run remotely by our Password Management software that runs iMacros currently.
Here is the current vbs script we use for iMacros:
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’
‘’‘’‘’ MAIN ‘’‘’‘’
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’
On error resume next

’ Actions
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’
Const ACTION_TYPE_VERIFY = “verifypass”
Const ACTION_TYPE_CHANGE = “changepass”
Const ACTION_TYPE_RECONCILE = “reconcilepass”
Const ACTION_TYPE_PRE_RECONCILE = “prereconcilepass”
Const ACTION_TYPE_LOGON = “logon”

‘Declarations
‘’’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’
Dim Rc
Dim LogonPassword
Dim CurrentPassword
Dim NewPassword
Dim ReconcilePassword
Dim ExtractedData
Dim timeout

if WScript.Arguments.Count < 8 Then
RaiseException -1, “Missing arguments. Usage " & wscript.ScriptName & " /action: /macro: /logonuser: /logonaddress: /username: /reconcileuser: /timeout: /debug: [additional args]”
End If

’ Get the logon password
Wscript.StdOut.Write wscript.ScriptName & " Enter the password used for logon: "
LogonPassword = Wscript.StdIn.ReadLine

’ Get the current password
Wscript.StdOut.Write wscript.ScriptName & " Enter the current password: "
CurrentPassword = Wscript.StdIn.ReadLine

’ Get the new password
Wscript.StdOut.Write wscript.ScriptName & " Enter the new password: "
NewPassword = Wscript.StdIn.ReadLine

’ Get the reconcile password
Wscript.StdOut.Write wscript.ScriptName & " Enter the reconcile user password: "
ReconcilePassword = Wscript.StdIn.ReadLine

’ Initialize the iMacros browser (Chrome=cr, IE=ie, iMacros=ng)
set ObjiMacros = CreateObject(“imacros”)
Rc = ObjiMacros.iimOpen(“-cr”, True)

ErrorHandler Rc, “Failed to initialize iMacros Browser”, ObjiMacros

'replace all args based on command-line names
Set objArgs = Wscript.Arguments
For i = 4 to objArgs.Count-1
ArgName = GetArgName(objArgs(i))
Arg = GetArg(objArgs(i))
Rc = ObjiMacros.iimSet(ArgName, Arg)
ErrorHandler Rc, "Failed to initialize variable " & ArgName, ObjiMacros
Next

'key-value pairs for hard-coded arguments
Dim varDictionary
Set varDictionary = CreateObject(“Scripting.Dictionary”)
'usernames and address
varDictionary.Add “username”, WScript.Arguments.Named(“username”)
varDictionary.Add “extrapass1username”, WScript.Arguments.Named(“logonuser”)
varDictionary.Add “extrapass3username”, WScript.Arguments.Named(“reconcileuser”)
varDictionary.Add “address”, WScript.Arguments.Named(“logonaddress”)
'passwords
varDictionary.Add “extrapass1”, LogonPassword
varDictionary.Add “pmextrapass1”, LogonPassword
varDictionary.Add “pmpass”, CurrentPassword
varDictionary.Add “pmnewpass”, NewPassword
varDictionary.Add “extrapass3”, ReconcilePassword
varDictionary.Add “pmextrapass3”, ReconcilePassword

'iterate through dictionary, set values
keys = varDictionary.Keys
For i=0 To varDictionary.Count - 1
key = keys(i)
value = varDictionary(key)
Rc = ObjiMacros.iimSet(key, value)
ErrorHandler Rc, String.Format(“Failed to initialize variable [{0}]”, key), ObjiMacros
Next

'Setting time default 90 seconds as timeout not recieved
timeout = WScript.Arguments.Named(“timeout”)
If (IsNull(timeout) Or (strComp(timeout,“”) = 0)) Then
timeout = 90
End If

’ Execute the task by playing the macro
macroPath = Left(WScript.ScriptFullName, InstrRev(WScript.ScriptFullName, ""))

Rc = ObjiMacros.iimPlay(macroPath & WScript.Arguments.Named(“macro”) & “.iim”, timeout)

ExtractedData = ObjiMacros.iimGetLastExtract()
Wscript.StdOut.Write ExtractedData

ErrorHandler Rc, "Failed to play the macro: " & WScript.Arguments.Named(“macro”), ObjiMacros

’ Check if we need to take screeshot, only in case debug is enabled
If (StrComp(WScript.Arguments.Named(“debug”), “Yes”, 1) = 0) Then

logPath = Left(macroPath, InstrRev(macroPath, "", Len(macroPath) - 1))
Rc = ObjiMacros.iimTakeBrowserScreenshot(logPath & “\Logs\ThirdParty\WebApp-” & WScript.Arguments.Named(“logonaddress”) & “-” & WScript.Arguments.Named(“username”) & “-” & Hour(Now) & “-” & Minute(Now) & “-” & Second(Now) & “.png”, 1)
ErrorHandler Rc, "Failed to take screen shot: ", ObjiMacros

End if

ObjiMacros.iimClose()
Wscript.StdOut.Write “DONE”
WScript.Quit 0

‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’
‘’‘’‘’ HELPER FUNCTIONS ‘’‘’‘’
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’
sub RaiseException(errCode, errDesc)
err.Number = errCode
err.Description = errDesc
ErrorHandler “An error has occured”
End sub

sub ErrorHandler(Rc, PrefixMsg, ObjiMacros)
If Rc < 0 Then
Wscript.Echo PrefixMsg & " (" & Rc & ", " & wscript.ScriptName & "): " & ObjiMacros.iimGetLastError()
ObjiMacros.iimExit()
Wscript.Quit Rc
End if
End sub

function GetArg(argument)
Dim a
a=Split(argument, “:”, 2)
GetArg=a(1)
End function

function GetArgName(argument)
Dim a
a=Split(argument, “:”)
GetArgName=Mid(a(0),2)
End function

What do you mean by remotely? Where is iMacros installed?

Rc = ObjiMacros.iimPlay(macroPath & WScript.Arguments.Named(“macro”) & “.iim”, timeout)

What is the path to the iMacros macro? Is it a local path or a network path? In any case, the same kind of path would work for Ui.vision macros as well.

Remotely is probably the wrong term to use, more like unattended.
The password management software will log into the server and run the vbs script which in turns runs the iMacros script.
If you are familiar with iMacros and CyberArk you’ll understand what I need this to do.
All of the scripts are local to one server, and will run with no “Human” intervention

Basically what I need to figure out is how to get the correct username from:
varDictionary.Add “username”, WScript.Arguments.Named(“username”)
To be entered into the username field of the webpage using &cmd_var1
arg = Chr(34) & path_autorun_html & “?storage=xfile&macro=” & macro &“&direct=1&savelog=”“&cmd_var1=” & username & “&cmd_var2=” & password & Chr(34)
Works fine, however the &cmd_var1 variable remains empty.
If I assign something to username, username = (“username”), that’s what get entered.
Need something similar to
username = WScript.Arguments.Named(“username”)
The username will change for every script and writing a .vbs for each one really isn’t feasible.

Inside the macro, the &cmd_var1=abc from the command is inside the ${!cmd_var1} variable (note the ! in front).