Share |

Marcus' Macro Blog

Mostly tips, tutorials, articles and news about Macro Scheduler & Windows Automation

Archive for the ‘General’ Category



Calling Macro Scheduler Functions from PowerShell

Monday, June 13th, 2011

Further to my post about the MacroScript SDK the other day, here’s an example of loading the MacroScript SDK COM object from PowerShell and running some Macro Scheduler code:

  $objMS = new-object -comobject "mscript.macroscript"
  $objMS.Init()
  $objMS.RunCode( "Run>notepad.exe" + [Environment]::NewLine +
  		"WaitWindowOpen>Untitled - Notepad" + [Environment]::NewLine +
  		"Wait>0.5" + [Environment]::NewLine +
  		"Send>Hello World", "")
  $objMS.Cleanup()

You will need to put the mscript.dll file into the system path (e.g. System32/SysWow64) or into the PowerShell folder.

Don’t forget that with the MacroScript SDK you can retrieve information and query the data back to PowerShell using the GetVar function (see previous post). So for all you system administrators using PowerShell but needing the GUI automation capabilities of Macro Scheduler as well, the MacroScript SDK is the perfect companion.

About the MacroScript SDK – How to Run Macro Scheduler Code Within Your Own Applications

Thursday, June 9th, 2011

What Is The MacroScript SDK?

The MacroScript Software Development Kit is a software component that allows developers to use the Macro Scheduler scripting language within their own applications. It comes in ActiveX and DLL form so that almost any programming language, including VB, C#, C++, Delphi, PowerBuilder, etc, can make use of it. It makes it possible for other applications to run Macro Scheduler code internally. As well as run Macro Scheduler code it allows the programmer to query or modify MacroScript variables at any point during execution.

Who Would Use It and Why?

The SDK is aimed at application developers. It is commonly used in projects where some integration is needed with other third party or legacy applications where no API exists, or where the developer needs to provide a means of creating macros within their applications.

For example, DM Software in Denmark used it in their Dialog Manager product to simplify integration with other systems and share data with them, as well as allow their users to create scripts for custom integrations. You can read the case study here.

Why Not Just Compile a Macro with Macro Scheduler Pro and “shell” it?

If all you want to do is have your application run a Macro Scheduler macro to perform some automation, then, sure, all you really need to do is compile your macro to a .exe and then call or “shell” this .exe from your application. E.g. using the VB/VBA Shell function.

This might be fine if that is really all you need to do. But what if you want to get data back from the macro? Let’s say the macro scrapes data from a web page and you need to get this data back into your calling application. This would be difficult to do with an external .exe. While you could use temporary file storage or a database and have your .exe macro write the data out and then read it back in with your application, this requires extra work and validation. You also have to consider the implications of the external macro process being terminated prematurely, perhaps by the user.

With the SDK you can execute script code directly from within your application in whole, or in sections or even one line at a time. And between lines or code sections you can directly query the value of a variable or variables. So using the SDK you have much greater control, there is no need to handle shelling out to an external process, waiting for it to complete and reading/writing to file. Instead you can control the logic flow as you wish and access macro data directly, storing it in local variables as and when needed.

- Control of logic flow
- Direct access to script variables
- No need to start an external process

How Do I Use It?

The MacroScript SDK ships with both an ActiveX and native DLL interface so is compatible with the majority of development environments and languages. A basic set of methods provides access to the functionality and examples are included for VB, VBScript, C++, C# and Delphi.

Here’s a simple example in VB:

    Set MacroScript = CreateObject("MScript.MacroScript")
    MacroScript.Init

    'Run notepad and send some text to it
    MacroScript.RunCode "Run>notepad.exe"
    MacroScript.RunCode "WaitWindowOpen>Untitled - Notepad"
    MacroScript.RunCode "Send>Hello World"

    'set variable x to the value entered in Text1 multiplied by 5
    MacroScript.RunCode "Let>x=" & Text1.Text & "*5"

    'get the value of x and put it in Text2
    Text2.Text = "x=" & MacroScript.GetVar("x")
    MacroScript.Cleanup

In the above example first we demonstrate running some code to start Notepad and send text to it. Next we create a MacroScript variable set to the value supplied in a text box on the form multiplied by 5 and then demonstrate how we can retrieve values back from the script.

As well as run script code you can also run script files and pass parameters into code blocks and scripts as you would command line parameters for regular scripts. In addition the ActiveX has script and parms properties and a Run method for an easy way to apply a script and run it.

For more information click here; download the evaluation which includes full documentation and examples; or read a case study on how DM Software makes use of the SDK in their Healthcare Application.

Customizing Message/Input Boxes

Wednesday, June 8th, 2011

Every now and then someone asks something like “How do I change the font in a modal dialog box?” or “Can I make an Input box multi-line?”.

Well, no, you can’t do those things to the standard Message/MessageModal or Input box functions. But, don’t forget that with Macro Scheduler you have the ability to create your own dialogs and make them act and feel pretty much any way you like. So the answer to the above questions, is “Create your own versions”.

As an example, let’s say you want a modal dialog that looks and acts much like the standard modal message box created by MessageModal. Only you want the text to be green in an italicized aerial font. Here you go:

//this would go at the top - customize as you wish
Dialog>CustomMsgBox
object CustomMsgBox: TForm
  Left = 493
  Top = 208
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  BorderStyle = bsSingle
  Caption = 'My Message'
  ClientHeight = 170
  ClientWidth = 319
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSMemo1: tMSMemo
    Left = 0
    Top = 0
    Width = 321
    Height = 137
    Font.Charset = ANSI_CHARSET
    Font.Color = clGreen
    Font.Height = -11
    Font.Name = 'Arial'
    Font.Style = [fsBold, fsItalic]
    ParentFont = False
    TabOrder = 0
  end
  object MSButton1: tMSButton
    Left = 121
    Top = 143
    Width = 75
    Height = 25
    Caption = 'OK'
    DoubleBuffered = True
    ModalResult = 2
    ParentDoubleBuffered = False
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>CustomMsgBox

SRT>ShowMsg
  SetDialogProperty>CustomMsgBox,,Position,poScreenCenter
  SetDialogProperty>CustomMsgBox,MSMemo1,Text,ShowMsg_Var_1
  Show>CustomMsgBox,r
END>ShowMsg

//do this to call your message
Let>MyMsg=Hello world, this is a lovely custom message box
GoSub>ShowMsg,MyMsg

And don’t forget that once created you can call the dialog any time you like. And if you want to use it in lots of scripts then put the dialog block and subroutine into an include file and use Include> at the top of each script you want to use it in.

Now, it’s over to you. Use your imagination and style the dialog any way you like. We have some Custom Dialog tutorials here: Part1, Part2

Letting off Steam?

Tuesday, June 7th, 2011

For the licensing mechanism for our ClipMagic product (ClipMagic is an easy to use Windows Clipboard Extender if you didn’t already know) we adopted a server based activation system. I know that some people have a passionate dislike for software that needs to be activated, but you can’t please everyone. And until now we’ve had no complaints.

Then yesterday we get a ticket with no name and an invalid made-up email address saying simply:

“Unfortunately I purchased your product without realizing it required web authorization. I’ll just use a competing product”.

Now, before I’d seen the email address my immediate reaction was to reply and offer a refund. Perhaps I’m too nice but I don’t see the point in having customers that don’t want to be customers. But then I noticed that if I did reply the email would simply bounce. The “customer” has provided no identifying information at all!

I don’t get it. He says he purchased but doesn’t want it – and won’t activate it. Yet doesn’t want me to know who he/she is and isn’t asking for a refund. So why bother emailing me? Letting off steam perhaps. But it seems odd that there was no request for a refund.

I’ll file it away in our “Strange Emails” category.

Why Can’t I Colour My Dialog Buttons?

Monday, May 23rd, 2011

Some people have asked why they can’t change the colour of a button that they place onto a custom dialog.

The short answer is that these buttons are standard Windows buttons and are drawn by Windows. And Windows has some “rules”.

Microsoft lays down some design guidelines. Take a look at this document here which says:

If you use standard windows and Windows controls, these border styles are supplied for your application automatically. If you create your own controls, your application should map the colors of those controls to the appropriate system colors so that the controls fit in the overall design of the interface when the user changes the basic system colors.

So, a standard control, like a dialog button will adopt the colour and design as decided by Windows and the user’s system wide preferences and we as the programmer have little or no control over it. Idealistically this is a good thing.

I believe that convention helps usability. If all buttons look alike a user knows it’s a button and so it’s purpose and functionality is obvious.

Of course, there are exceptions and sometimes there may be a reason (justified or not) for ignoring the guidelines and making a button look like something very different, e.g. in a game. So how do you do it? Well, obviously you don’t use standard Button objects.

On the whole Macro Scheduler dialogs are meant to be just that – standard looking Windows dialogs, designed for requesting data from users or giving them choices and controlling macros.

If you want complete freedom to design something snazzy then arguably you are using the wrong technology and should be considering something like Flash or HTML instead. And there’s no reason why such an interface can’t trigger Macro Scheduler macros anyway.

Having said that there are some things you can do to make more glorified looking dialog “buttons”. One option is to use Image objects. Don’t forget that you can respond to a mouse click on any object, so you can easily have a clickable image. You can trap other events too – such as mouse over events. So if you want to be really clever you can have your image’s mouse over event change the image, e.g. to one with a slightly different border style so that the user knows it is the active “button”.

Authenticate Your EXEs – Discounted Code Signing

Tuesday, April 26th, 2011

What is Code Signing?

Since XP, when you download an executable file from the Internet the browser checks the file’s Authenticode signature. This verifies who the publisher is. You get a dialog asking if you wish to download software from this publisher. If there is no signature the warning is more severe and it says something like:

The publisher could not be verified. Are you sure you want to run this software? This file does not have a valid digital signature that verifies its publisher. You should only run software from publishers you trust.

In some cases you will also get a similar warning when running applications that haven’t been signed, especially if the executable resides on a network drive. Apps that have been signed are trusted more by the operating system. Vista and Windows 7 are more fussy and certain types of app must be signed.

Code signing protects against tampering and impersonation. If a signed app is tampered with or modified in some way the signature becomes invalid and so the user will be warned when they try to run it.

How does it work?

A publisher applies for a digital certificate from a Certification Authority like Comodo or Verisign. Using the Microsoft Authenticode tools the publisher can sign their applications with their digital certificate. The signing tool basically makes a hash of the code and their private key and appends the signature to the end of the executable. If the code is later modified the signature will therefore be invalid as it is partially based on the application’s code itself.

Should I sign EXEs Compiled with Macro Scheduler?

If you distribute compiled macros to others, or let people download them from the web you should definitely be signing them. Users can then see who the publisher is and be sure that the file hasn’t been modified in any way, and will no longer see the unknown publisher warning presented by the web browser/operating system.

So how do I sign my EXEs?

First you need to obtain an Authenticode Certificate. We have negotiated a very helpful 10% discount for our customers off the price of Comodo Code Signing certificates supplied by K Software, an official Comodo Reseller. K Software prices are already extremely competitive and now, as a Macro Scheduler user, you get an extra 10% off.

The certificate used to sign our software, including Macro Scheduler was supplied by K Software. So you know you are in good company! :-)

To find out more and place an order visit K Software’s Code Signing page. To get your 10% log into the Macro Scheduler Registered Customer area to obtain your special discount code.

You also need the code signing tools. These come with the Microsoft Platform SDK and can be downloaded here:
Platform SDK Redistributable: CAPICOM

Once installed, launch SignTool.exe to sign your EXE. For command line options see: Sign Tool (SignTool.exe)

For more step by step help Jeff Wilcox has written an excellent article about code signing and authenticode. It covers everything from the order process through the tools you’ll need to do the signing. Read the article about code signing here.

Rewarding Feedback

Thursday, February 10th, 2011

I received this in an email yesterday and just had to share it:

“Thank you for a truly superior product! I used this at a previous place of employment and developed a system to autopopulate our very static software. When the software vender sent training staff they were so impressed they offered me a job! I now work for them and have you to thank for it!”

It’s not always easy running a small software company. But receiving feedback like that certainly makes up for a lot of hard work.

A Few Site Changes – New Helpdesk and Sharing Links

Thursday, February 3rd, 2011

For years now we’ve been making do with a less-than-perfect open source ticketing system. We’ve lived with missing attachments, emails not always getting through and the lack of embedded images, some garbled mime encodings and various other missing features.

Finally we have a brand spanking new helpdesk. It’s over at help.mjtnet.com. You can still email us as usual. And if you’ve emailed us recently you may have noticed the receipt of some snazzier looking emails containing your ticket history. You can also submit and view the status of tickets online. You may also have noticed that a “Feedback” tab has appeared to the left of the website. This is a quick way to send us a message from whatever page you are on (except the forums – we figured if you’re on the forums you would want to post a forum message not send an email).

Another new feature on the website is social networking sharing buttons. You’ll notice Twitter and Facebook buttons on each blog post. Facebook “like” buttons have also now appeared after every forum post, and at the top of every page you’ll see Facebook, Twitter and other bookmark buttons. So if you see a post or page you like please share it, or bookmark it and help introduce people to the world of Macro Scheduler!

Don’t forget you can also connect with us and other Macro Scheduler fans on the Macro Scheduler Facebook page, or follow my occasional tweets on Twitter.

So, whether by Facebook, Twitter, Forum, Email or Helpdesk, I look forward to chatting with you. :-)

15% Off T-Shirts Today at Zazzle

Tuesday, December 14th, 2010

Thought I’d share this: I just noticed that Zazzle are currently offering 15% of all orders today (14th December) only with code JINGLESALE75. Also free shipping on orders over $50. More details are here. So if you were thinking of grabbing a shirt (even if it’s not one of ours!) now could be a good time!

Macro Scheduler T-Shirts and Merchandise

Monday, December 13th, 2010

With Christmas round the corner I thought I might post a reminder that we have a number of official logo T-shirts, mugs and mouse mats available via Zazzle.com: