November 15, 2010

Creating Native Function Aliases for Win32 Functions

Filed under: General,Scripting — Marcus Tettmar @ 11:08 am

The other day I posted a response on the forums which uses LibFunc to run the Win32 API function GetKeyState. This prompted someone to email me the following:

I didn’t know the Win API call to check for a key being down. The API call works but have you considered adding a native MS command called KeyDown> or maybe CheckKeyDown>

Well, it’s already possible to create native looking functions for DLL functions and therefore Win32 API functions.

We can do this by creating an Imports file in the Imports sub folder of Macro Scheduler. Let’s make an import file for some functions in User32.dll:

Step 1. If you don’t already have an Imports subfolder inside the Macro Scheduler program folder, create one: c:\program files\Macro Scheduler12\Imports

Step 2. Create a symbolic link to the appropriate DLL in this folder. Start a CMD prompt and CD to the Imports folder and for User32.dll type the following:

mklink user32.dll c:\windows\system32\user32.dll

If on a 64 bit system replace system32 with syswow64

This will create a link to the DLL in the Imports folder. Next we need to make a corresponding INI file.

Step 3. Create a file called User32.ini in the Imports folder. Inside this file create entries for each function you wish to import. E.g.:

[GetKeyState]
FunctionName=GetKeyState
Parms=1
Parm1=INT

[SendMessage]
Parms=4
Parm1=INT
Parm2=INT
Parm3=INT
Parm4=INT

[FindWindow]
Parms=2
Parm1=PCHAR
Parm2=PCHAR

Now, instead of writing:

Let>VK_UP=38
LibFunc>user32,GetKeyState,result,VK_UP

You can write:

Let>VK_UP=38
GetKeyState>VK_UP,result

So here’s a project for someone or a group of people: Create a User32.ini file for a fuller list of compatible functions which we can share on the website. Any function that accepts either integers (INT) or strings (PCHAR) and returns an integer (or nothing) can be included. And then we want another one for Kernel32.dll … etc.

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

Macro Scheduler on Facebook!

Filed under: Announcements,General — Marcus Tettmar @ 3:43 pm

If you’re a Facebook fan you can now find Macro Scheduler there too. So head on over and say hello. Here’s the URL:

http://www.facebook.com/pages/Macro-Scheduler/122209210925

June 23, 2010

Associating a File Extension with a Compiled Macro

Filed under: General,Scripting — Marcus Tettmar @ 10:14 am

I have a few scripts which perform actions on files. Rather than have the script ask me what file to use, it is easier to associate the file type with the script so that I can just double click on the file (or right click and choose “Open with”) in Windows Explorer.

For this to work the script must first accept a file on the command line. Here’s a really simple script which reads the content of a file passed into the script with the “thefile” command line parameter:

ReadFile>%thefile%,fdata
MessageModal>fdata

If you were to compile this script and then pass thefile on the command line it would read in the file content and display it in a message box:

c:\path\myexe.exe /thefile=c:\somefile.mjt

Now, if we create a file association for .mjt files we would only need to double click on the .mjt file to have it open in the exe.

The easiest way to create a file association for a file that does not already have one is to just double click on the file in Windows Explorer. Then when asked choose to select from a list of installed programs and on the next dialog click on the “Browse” button to locate your executable.

If the file extension is already associated with other applications then right click on the file and choose “Open With” and then “Choose program…”, then UNCHECK “Always use the selected program to open this kind of file” and click on “Browse” to locate your executable.

Initially this won’t quite work. We need to make a small change, as this creates a mapping in the registry which looks like this:

“c:\path\myexe.exe” “%1”

We want to change it to:

“c:\path\myexe.exe” /thefile=”%1″

So after creating the file association via Windows Explorer we need to make a small registry change:

1. Fire up RegEdit.exe (Start/Run and then type regedit.exe)
2. Open HKEY_CLASSES_ROOT
3. Search for your exe name to find the “c:\path\myexe.exe” “%1” entry
4. Make the change as above, changing the “%1″ to /thefile=”%1”

Now, when you double click the file (or right click/Open with) it will launch your exe, with the filename passed to it in the “thefile” parameter.

You could actually code the script in such a way that you don’t need to do the registry change. You could parse the COMMAND_LINE system variable to get the file from the command line, without requiring a custom parameter name. This is discussed in this forum post which talks about being able to drag and drop a file onto a script.

If you want to create the file association programmatically, take a look at what registry entries are created by Windows when you do it manually. Then you can use the registry functions to achieve the same. E.g. this script associates .why files with the “c:\where\why.exe” executable expecting the file in a parameter called “thefile”:

RegistryWriteKey>HKEY_CLASSES_ROOT,.why,,why_auto_file
RegistryWriteKey>HKEY_CLASSES_ROOT,why_auto_file\shell\open\command,,"c:\where\why.exe" /thefile="%1"

May 21, 2010

Weekly Forum Round-up

Filed under: Automation,General,Scripting,Testing — Marcus Tettmar @ 10:34 am

I thought I might start a weekly round up of some of the Macro Scheduler forum posts that caught my eye during the week. Not everyone gets a chance to browse the forums all the time, so it might help to link to some here. Then those that subscribe to the blog via RSS/Email will see them and they’ll also show up in Macro Scheduler’s News Feed window.

The forums are quite active but I won’t link to every little discussion or request for support – just those that demonstrate a new feature, or work as a “how to” or anything else that I think could be useful. We’ll see how it goes.

So here’s my list for week ending 21st May 2010:

How to trim spaces from the ends of, or within, a string

A Progress Bar Demo using Macro Scheduler 12

How to make a custom dialog minimize to the task bar

Putting a status bar with multiple panels on a custom dialog

Finding a drive based on its label (volume name)

Getting the HTML source of a page using WebRecorder

Running Automated Testing scripts in the background via VMWare

May 20, 2010

Sharing and Synchronizing Macros

Filed under: General — Marcus Tettmar @ 3:15 pm

A new feature in Macro Scheduler 12 is the ability to easily share macros with other people on your network, or between desktops.

It has long been possible to work outside of the Macro Scheduler interface and indeed many people already do this. You can use the standalone editor and run or edit macro script files (.scp) directly from Windows Explorer. So to share script files you can store them in a network folder which each person in your team can access.

But until now that had some limitations. Firstly you would have to work outside of the Macro Scheduler interface and secondly, until version 12, scripts weren’t opened exclusively. So if two people were working on a script at the same time the last person to save would overwrite the changes made by the first. Until now Macro Scheduler was not built with network sharing in mind. And of course if you wanted to apply a schedule, trigger, or hot key to a shared macro you would need the Macro Scheduler interface. So would need to import it. Therefore any time it was changed you’d have to re-import it again.

Linked Groups and Exclusive Opens

With Macro Scheduler 12 you can now create “Linked” macro groups. Version 12 also makes sure that when you open a script for editing it is opened exclusively. This means the file is locked and no one else can open it until you’re done.

To create a Linked Group, create a new macro group as you would normally, set the path of the group to point to a network share, and check the “Create Linked Group” box. Give it a name and click OK.

Any macros already in the folder will show up immediately. And if you create a new macro in that group (or move a macro to it) other people with a group linked to the same folder will see those macros too.

So Linked Groups are useful where you want to easily share macros between members of your team or between two desktops – e.g. your desktop and your laptop.

You could also share macros between a developer and several users and prevent the user from being able to edit them by using a network share that you can write to but they only have read only access to. The users would be able to run the macros but not edit them or create new ones in that group.

Note that at present to delete a macro from a Linked Group the file needs to be deleted from the folder using Windows Explorer. This is partly to avoid accidental deletes and to prevent people from moving linked macros. We are considering ways of improving on this in future so that linked groups can be administered more easily within Macro Scheduler. It’s early days for Linked Groups and I’m sure as more people start to use them ideas will start flowing in. So if this is something that becomes popular expect improvements over time.

April 23, 2010

Using an Old Version? Time to Upgrade for Vista/Win7 Support.

Filed under: General,Macro Recorder — Marcus Tettmar @ 9:50 am

If you’re using an old version of Macro Scheduler, especially version 8 or lower, and like many others, you or your company are considering upgrading your Windows operating system to Vista or Windows 7 soon then you will need to consider upgrading Macro Scheduler too.

Windows 7 adoption rates are outpacing those of Vista fast and many companies are planning on going straight from XP to Windows 7. Already Windows 7 has over 15% market share with over 90 million licenses sold as of March 2nd.

Version 8 of Macro Scheduler was superseded before Windows Vista came along. And Vista brought with it some changes that required us to make changes to Macro Scheduler. So Macro Scheduler v9 was the first version that fully supported Vista. The latest version supports Vista and Windows 7 fully and is listed at Microsoft.com as a “Windows 7 Front Runner” application.

One of the things that Vista introduced were the thumbnail windows that appear when you hover over a task bar icon. These have the same title as the application’s main window. So in Macro Scheduler 8.0 and lower you will run into a problem where your SetFocus lines and other window functions find this thumbnail window before the main window and prevent your scripts from working properly.

Starting with Macro Scheduler 9.0 (in 2007) we made the window functions ignore these new thumbnail windows to prevent this problem. We also had to make some changes to the macro recorder. Older versions may not be able to record under Vista without running Macro Scheduler as admin.

So if you’re still running Macro Scheduler 8 or below then even if you have no plans to change your macros, you’re going to need a newer version when your operating system is upgraded to Windows 7.

Furthermore, we can’t support old versions forever and with the release of version 12 we will be discontinuing support for versions 8 and lower. Since version 9.0 was the first version that properly supported Vista and above we can only really continue to provide support for this version and onwards.

Version 12 offers even more Vista/7 functionality including a reliable AutoLogon mechanism that works in Vista/7/2008 to allow you to schedule macros to run even when Windows is locked or logged out.

So now is the time to upgrade. And if you buy or upgrade to v11 now, we’ll give you a free upgrade to v12 when it is released in a few weeks.

So there’s really no need to wait.

For a summary of new features in v12 click here and here.

The best way to upgrade is to log into your registered account and click the upgrade links. Any problems accessing your account email us.

Consider adding maintenance to your order as well. This will ensure you continue to get all future upgrades and new features automatically at no extra cost. Maintenance is the easiest way to ensure your software stays up to date with all the new Windows releases.

Take a look at the Macro Scheduler history list to see how many improvements there have been since version 8:
http://www.mjtnet.com/mswhatsnew.htm

April 20, 2010

GearHead Hero Movie

Filed under: General — Marcus Tettmar @ 2:26 pm

Have you seen the movie?

http://en.tackfilm.se/?id=1271773406310RA59

🙂

March 8, 2010

Screen Magnifier In Only 34 Lines of Code

Filed under: General,Scripting — Marcus Tettmar @ 9:46 am

Check out this screen magnifier, written by Dick Lockey in only 34 lines of Macro Scheduler code.   Paste it into a macro, hit run and then as you move the mouse around your screen you’ll see a 5x magnification of the cursor area.

Dialog>Dialog1
   Caption=5X Magnify
   Width=800
   Height=500
   Top=500
   Left=48
EndDialog>Dialog1
Show>Dialog1
  LibFunc>user32,GetDC,HDC1,Dialog1.handle
  LibFunc>user32,GetDC,HDC3,0

Label>Loop
  GetDialogAction>Dialog1,res1
  If>res1=2
    Exit>0
  EndIf
  GetCursorPos>CurX,CurY
  Sub>CurX,80
  Sub>CurY,50
  Wait>0.01
  LibFunc>Gdi32,StretchBlt,SBres,HDC1,0,0,800,500,HDC3,CURX,CURY,160,100,13369376
  GoSub>DrawLine,Dialog1.handle,1,0,390,250,410,250
  GoSub>DrawLine,Dialog1.handle,1,0,400,240,400,260
Goto>Loop

SRT>DrawLine
  LibFunc>user32,GetDC,HDC,%DrawLine_var_1%
  LibFunc>gdi32,CreatePen,Penres,0,%DrawLine_var_2%,%DrawLine_var_3%
  LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
  Libfunc>gdi32,MoveToEx,mtres,HDC,%DrawLine_var_4%,%DrawLine_var_5%,0
  LibFunc>gdi32,LineTo,ltres,hdc,%DrawLine_var_6%,%DrawLine_var_7%
  LibFunc>gdi32,DeleteObject,DOres,Penres
  LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawLine

Yes, as Dick Says, you get one of these with Windows. But it’s kind of cool to see you can do the same thing with Macro Scheduler, and the code might come in handy elsewhere.

Enjoy.

March 4, 2010

Choose Your Web Browser

Filed under: General,Web/Tech — Marcus Tettmar @ 10:39 am

One of my Windows XP systems installed an automatic update last night when I shut it down.  This morning I was presented with this:

Windows EU WebBrowser Choice

As I understand it this is as a result of an EU competition law decision.   Is this a good thing or a bad thing?

On the one hand it seems a waste of money and illogical.

I’m no fan of IE, but why shouldn’t Microsoft build a web browser and make it part of their operating system?  Should the EU force them to offer a choice of text editors, calculators, paint programs and calendar applications too? Where should it end?

Plus, yet another dialog like this is surely going to confuse the ordinary user.  Many have no idea what a “web browser” is and just call it “My Internet” or “Google”.  The dialog preceding the one above has to go to the trouble of explaining what a web browser is.  And isn’t the user just going to take the first option anyway?  In which case should the EU force Microsoft to make IE8 something other than the default option?

But then if I were trying to sell a web browser I guess I would welcome this decision. It might give me a little extra exposure.

What do you think?

« Newer PostsOlder Posts »