September 15, 2010

Accessing 64 bit System Folders – Turn off File System Redirection

Filed under: Automation, General — Marcus Tettmar @ 8:50 am

If you need to run a 64 bit system command, or a system command that requires access to the 64 bit system folders you may need to turn off File System Redirection.

To turn off File System Redirection call the snappily named Wow64DisableWow64FsRedirection function and remember to turn it back on with the equally memorable function Wow64RevertWow64FsRedirection.

For example:

//turn off File System Redirection
LibFunc>kernel32,Wow64DisableWow64FsRedirection,result,0

Let>RP_ADMIN=1
let>RP_WAIT=1
DeleteFile>%TEMP_DIR%\vss.txt
Run>"cmd.exe" /c vssadmin list shadowstorage  >> "%TEMP_DIR%\vss.txt"
ReadFile>%TEMP_DIR%\vss.txt,vss
MessageModal>vss

//revert File System Redirection
LibFunc>kernel32,Wow64RevertWow64FsRedirection,result,0

Recently someone running the 64 bit version of XP was having a problem running this innocuous looking code:

Run>c:\windows\system32\mstsc.exe

mstsc.exe is the remote desktop client. Macro Scheduler returned an error saying that c:\windows\system32\mstsc.exe could not be found, yet using Windows Explorer we could see mstsc.exe clearly in the system32 folder. The same code worked perfectly fine on a Win7 x64 system.

Eventually I realised what was happening. Because the OS was 64 bit and Macro Scheduler is 32 bit, Windows was redirecting “c:\windows\system32\” to “c:\windows\syswow64” – the 32 bit system folder. There should be a 32 bit version of mstsc.exe in there, but on this particular system it was missing (it may be that earlier versions of Remote Desktop on x64 did not install a 32 bit version). Hence the error that Macro Scheduler could not find the file. We quickly resolved this by turning off File System Redirection using the code above.

Although the current 32 bit version of Macro Scheduler runs on and is compatible with all 64 bit versions of Windows, a 64 bit version of Macro Scheduler is in the pipeline. Until then calling some system level functions may need the above treatment if those commands need to access the 64 bit subsystem. Macro Scheduler can happily execute and interact with 64 bit applications, but Windows will redirect references to some locations such as system32 unless File System Redirection is disabled.

September 14, 2010

September 8, 2010

Trigger Scripts

Filed under: Automation, Scripting — Marcus Tettmar @ 3:03 pm

Macro Scheduler has a number of scheduling features to allow you to specify when a macro should fire. One of these mechanisms is called a Trigger. There are several trigger types:

  • Window Event
  • File Event
  • Folder Event
  • Custom Event

A Window Event can be set to fire when a specified window appears or disappears. Similarly file events can be set to fire the macro when the specified file exists or ceases to exist. Folder events offer much the same (a folder exists or ceases to exist) but also a little more. A Folder event can also be configured which will fire the macro when a new file appears in the folder, or a file is removed from the folder.

New File Triggers

With a “New File in Folder” trigger the macro will fire whenever a new file appears in the folder, regardless of what that file is called. This can be very useful and is often used to detect incoming files for further processing. In a situation like this we would need to detect that a new file has appeared and then do something with it. Using the New File in Folder trigger will cause the macro to run, but then we need the macro to determine what that file is called. We can do that with a VBScript function which returns the newest file in a folder:

VBSTART
Function NewestFile(Folder)
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(Folder)
dPrevDate = "0"
For Each oFile In oFolder.Files
  If DateDiff("s", dPrevDate, oFile.DateLastModified) > 0 Then
    sNewestFile = oFile.Path
    dPrevDate = oFile.DateLastModified
  End If
Next
NewestFile = sNewestFile
End Function
VBEND

We can then call it like this:

VBEval>NewestFile("c:\downloads"),filename

This will return in filename the path of the newest file in the given folder. So if our macro is fired by a new file appearing in a folder it can then run this code to get that file’s path and do something with it.

Custom Triggers

Custom triggers allow you to create any kind of trigger you can think of by executing Macro Scheduler code. Maybe you want to monitor the contents of a text file or an INI file entry, a registry entry or the size of a specific file. If you can code the check in Macro Scheduler you can create a trigger out of it.

Custom triggers work by linking to a script (.scp) file which contain two subroutines. One subroutine is called Trigger and the other Reset. Initially the Trigger subroutine is called repeatedly until it sets MACRO_RESULT to TRUE. Thereupon Macro Scheduler calls the Reset routine instead until it too sets MACRO_RESULT to TRUE and the cycle then continues.

By way of an example lets say we want to trigger a macro based on the value of an INI file entry. Let’s say our INI file looks like this:

[MyStuff]
Color=red

Let’s say we want to trigger a macro to run when the Color entry in the INI file gets set to “blue”. Here’s our trigger script:

SRT>Trigger
  ReadIniFile>d:\files\myini.ini,MyStuff,Color,gColor
  If>gColor=blue
    Let>MACRO_RESULT=TRUE
  Endif
END>Trigger

SRT>Reset
  ReadIniFile>d:\files\myini.ini,MyStuff,Color,gColor
  If>gColor<>blue
    Let>MACRO_RESULT=TRUE
  Endif
END>Reset

So here the Trigger routine which is executed continually by the scheduler will return TRUE only if Color in the INI file becomes equal to “blue”. Thereupon the Reset routine will be executed which will reset the trigger when Color is no longer “blue”. After that the Trigger routine is executed again.

Since Trigger routines are run frequently on a very tight interval they should be kept as small as possible and should not be long running. Don’t make Trigger scripts that perform too much complicated processing or include delays as this could cause resource issues. Sometimes, for more complicated “triggers” or monitoring scripts you may be better off creating a looping macro or repeating macro. E.g. if you wanted to poll a POP3 server for an email message containing specific content this is a more time consuming process subject to network delays so would probably not be a good candidate for a Custom Trigger. Instead create a macro which checks the email every few minutes, or one that loops continuously.

August 24, 2010

Don’t Overwhelm your Target!

Filed under: Automation, Scripting — Marcus Tettmar @ 4:24 pm

When sending keystrokes to other applications remember that Macro Scheduler works much faster than a human being can type. Many applications do form field verification or background processing on the fly as the text is received. And most applications were designed on the assumption that a human being would be operating them. It may not have occurred to the developers that a robot might try to send a stream of text to the UI at the rate of 5000 characters a second!

With some applications if you try to send too many characters at once you may find that some of those characters fail to show up, or the string is truncated.

The solution should be obvious by now. That is to slow down the key send rate. You can do this easily by setting the SK_DELAY parameter which introduces a specified millisecond delay between each character.

Let>SK_DELAY=20
Send>long_string

Of course you could break the long string down into smaller chunks and insert a delay between them:

Send>part_1
Wait>0.3
Send>part_2
Wait>0.2
Send>part_3

But SK_DELAY is simpler and easier if you can’t control the length of the data easily.

A related issue I see every now and then is when “tabbing” from one field to another on a form. Pressing the tab key moves the focus to the next field, so we use this while sending data into a form. Sometimes we’ll encounter an application which needs a bit of time after a field has been focused before it can accept data, or the other way around. So sending Tab immediately after/before sending the data with no delay fails to work. Adding in a small delay between sending the data and the Tab solves it:

Send>field_data
Wait>0.3
Press Tab

Wait>0.3
Send>next_field
Wait>0.3
Press Tab

etc

Similarly when we need to tab through lots of fields at once without sending data we may try to save ourselves coding time by writing:

Press Tab * 10

But if the app needs time to react between each tab we may have to split that out into separate tabs with delays between them or replace with a repeat/until loop:

Let>tabs=0
Repeat>tabs
  Press Tab
  Wait>0.2
  Let>tabs=tabs+1
Until>tabs=10

As I’ve said many times before the most common causes of things not working as expected are either timing or focus. Macros run way faster than a human can type which is often beneficial but if things aren’t quite right start off by slowing the macro down a bit. You can always speed it up later!

August 6, 2010

Macro Scheduler 12.0.6 Update Available

Filed under: Announcements — Marcus Tettmar @ 3:34 pm

Macro Scheduler 12.0.6 is now available with the following fixes:

  • Added: SetDialogObjectFont can now ADD a style to the font (subsequent calls with a different style value will apply that value to whatever the existing style is (e.g. Bold, then Italic)
  • Added: WIN_SLEEP option can be set to 1 to cause WaitWindowOpen/Closed or OnEvent WINDOW_OPEN/NOTOPEN to yield to processor more (slower but less CPU usage)
  • Fixed: ExecuteFile was limited to command lines of length MAX_PATH. Limit removed.
  • Fixed: SetDialogObjectFont unable to reset font style to normal by setting font style to 0 (zero)
  • Fixed: VAREXPLICIT variable is not retrieved properly

Workflow Designer and the SDK have also been updated to the same MacroScript version.

Registered Downloads/Upgrades | Evaluation Downloads | New License Sales

July 26, 2010

Practical Software Test Automation Course Now Available in e-Learning!

Filed under: Announcements, Testing — Marcus Tettmar @ 11:07 am

Rice Consulting have just announced that their new Practical Software Test Automation Course – which features Macro Scheduler for the scripting exercises – is now available in an e-Learning format.

This course focuses on the basics of software test automation and expands on those topics to learn some of the deeper issues of test automation. This course is not specific to any particular tool set but does include hands-on exercises using free and inexpensive test tools. The tool used for test automation exercises is Macro Scheduler.

The main objective of this course is to help you understand the landscape of software test automation and how to make test automation a reality in your organization. You will learn the top challenges of test automation and which approaches are the best ones for your situation, how to establish your own test automation organization, and how to design software with test automation in mind. You will also learn many of the lessons of test automation by performing exercises using sample test automation tools on sample applications.

I’ve been running through the course myself and so far I’m really impressed. This is a great way to get started on test automation and the great value e-Learning format means you can do it in your own time at your convenience. There’s also a whole module on using Macro Scheduler with some videos to help you get started.

You can see the course outline here, take a demo, or sign up on line here.

July 14, 2010

Launching URLs in Default Browser (and a small bug!)

Filed under: Automation, Scripting — Marcus Tettmar @ 10:06 am

A quick and easy way to launch a URL in the default web browser is just to use the ExecuteFile command:

ExecuteFile>http://www.mjtnet.com/

However, I have recently discovered that ExecuteFile is currently limited to a command line length of MAX_PATH (260 chars) and that if more than 260 chars are passed it will cause Macro Scheduler to crash. This is a bug that we’ll get fixed in the next update (increase the limit if possible AND prevent a crash if more chars than can be handled are passed).

Another way to launch a URL in the default browser is to use the Run command. First you need to determine the path to the default browser which you can do by querying the registry:

Let>url=http://www.mjtnet.com/

//get path of default browser ...
RegistryReadKey>HKEY_CLASSES_ROOT,htmlfile\shell\open\command,,browserEXE

Run>%browserEXE% %url%

July 12, 2010

Macro Scheduler 12.0.5 Update Available

Filed under: Announcements, Macro Recorder — Marcus Tettmar @ 10:11 am

Macro Scheduler 12.0.5 is now available with the following fixes:

  • Fixed: PNG images added to custom dialogs not saving correctly and therefore not displaying when dialog opened or script run.
  • Fixed: LClick and RClick not independent of left hand/right hand mouse settings (LCLick should always do primary button function).
  • Fixed: GetDialogProperty not retrieving properties of parent dialog itself (when object name ommitted).
  • Fixed: “The procedure entry point WTSUnRegisterSessionNotification could not be located in the dynamic link library wtsapi32.dll.” under Windows 2000.
  • Fixed: Macro Recorder failing to properly record window titles containing a colon character.
  • Fixed: Error messages in compiled scripts showing garbage instead of file name.

Workflow Designer and the SDK have also been updated to the same MacroScript version.

Registered Downloads/Upgrades | Evaluation Downloads | New License Sales

July 5, 2010

Success Story: Automated Information Retrieval and Report Production

Filed under: Success Stories — Marcus Tettmar @ 2:12 pm

This was posted to the forum recently and I thought I would share:

I’m currently using [Macro Scheduler] to pull aviation electronic manufacturing information from a SAP database, compile into a MS Access database, then generate a report such that the data becomes useful information needed to identify and prioritize manufacturing tasks and processes across a diverse profile of complex systems being manufactured.

Had to spend hour+ (heavy on the +) every day spread out throughout an entire shift getting this information manually. Often, due to the length of time to acquire the info, the information would be derived too late in the shift to make good use of it. Lost opportunities and manufacturing delays galore.

The information can now be gleaned by anyone within minutes. The entire department is empowered to work smarter through making use of accurate real-time visual status information. Status is no longer hidden or obscure to visualize.

I was able to understand and adapt to the very easy to use Macro Scheduler structure with little frustration. I found that things I tried actually worked as anticipated and worked far more reliably than I dared hope for. When stuck, I found EXACTLY what information I needed in your forums. In fact, I ecstatically found differing superior methods in other areas of interest while searching for these solutions.

I haven’t had this much fun in decades. I want to thank the crew @ mjtnet and the users of Macro Scheduler for the efforts that brought enlightenment to me of a better way to do things.

Share YOUR story – what do you use Macro Scheduler for and how does it benefit you?

June 28, 2010

WebRecorder Update

Filed under: Announcements — Marcus Tettmar @ 3:35 pm

WebRecorder has been updated with a new version of the runtime component – IEAuto.DLL version 2.07.

This fixes a small bug preventing the ExtractTagByName function from extracting form field values. ExtractTag was working correctly but the same functionality to retrieve form field values was missing from ExtractTagByName.

Registered users can download the WebRecorder update from the registered downloads area.