PowerShell

(Copy URL in PhpBB Forum Format - Info)

From iMacros

Jump to: navigation, search

The iMacros Scripting Interface can be used from any programming or script language. The following example shows you how to call this interface from the Windows PowerShell. The macro is the PowerShell version of the Combine-Macros.vbs VBS script.

 #region Using
 [void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
 #endregion
 
 #region Helper methods
 
 function CreateObject($progID)
 {
 	new-object -com $progID
 }
 
 function MsgBox($string, $title = 'PowerShell Message')
 {
   $eat = [windows.forms.messagebox]::Show($string, $title)
 }
 
 function LogOnFailure($logFile, $macroName, $statusCode, $iim)
 {
 	if($statusCode -lt 0) {
 		$logFile.WriteLine($macroName + ": Error-No: " + $statusCode + " => Description: " + $iim.iimGetLastError())
 	}
 }
 
 #endregion
 
 #region Main code
 
 # This part is for the script specific error log (instead of popup messages).
 # The advantage of an error log instead of a popup is that the script 
 # continues running even after an error appears. An example of an error would
 # be a timeout due to a temporarily slow web site.  
 
 $OPEN_FILE_FOR_APPENDING = 8
 
 # Generate a logfile name based on the script name
 $logFileName = "./combine-macros-errorlog.txt" 
 $fileSystemObject = CreateObject("Scripting.fileSystemObject")
 $logFile = $fileSystemObject.CreateTextFile($logFileName, $True)
 $logFile.WriteLine("Error Log for COMBINE-MACROS.VBS demo script")
  
   
  $iim1 = CreateObject("imacros")
   
   $i = $iim1.iimInit()
 LogOnFailure $logFile "INIT"  $i  $iim1
 
 $i = $iim1.iimPlay("wsh-start")
 LogOnFailure $logFile "WSH-START" $i $iim1
 
 $i = $iim1.iimPlay("wsh-lunch")
 LogOnFailure $logFile "WSH-LUNCH" $i $iim1
 
 $i = $iim1.iimPlay("wsh-submit-button")
 LogOnFailure $logFile "WSH-SUBMIT" $i $iim1
 
 $i = $iim1.iimExit()
 LogOnFailure $logFile "EXIT" $i $iim1
 	
 # This part is for the script specific error log (instead of popup messages).
 $logFile.Close()
 
 #endregion
Personal tools
Home
Toolbox

Website Monitoring