March 1, 2010

Convert raw VBScript .vbs files to Macro Scheduler Scripts

Filed under: Scripting — Marcus Tettmar @ 2:34 pm

As you probably know Macro Scheduler scripts can include Microsoft VBScript. Not only can you CALL VBScript code you can also pass values into it and retrieve values out of it (I’ve seen many competitors claim you can use VBScript in their macros when what they really mean is you can only call external VBScripts and not get results and data back).

This means you can take VBScript code and embed it into your macros. However, you may need to make some small modifications to VBScript code samples you find out there in the wild, and I’m often being asked how to do this.

Usually the only changes necessary involve the fact that many sample scripts are designed to run as standalone .VBS files and make use of the WScript object. This object is instantiated automatically by the Windows Scripting Host and offers methods like “Echo” and “Sleep” which you’ll often see in sample scripts. But in the case of Macro Scheduler VBScript is being hosted by Macro Scheduler, not the Windows Scripting Host, so WScript is not available.

Therefore anything starting with WScript will need to be removed or replaced with something else.

The most common one is WScript.Echo. This simply displays a message. When the VBS file is run on the command line the message is output to the command line. Otherwise it appears in a pop up message box. Most of the time in sample scripts it is just there as an example, so you can see the code working. You’d probably end up not wanting the script popping lots of message boxes anyway. But if you do you could replace it with MsgBox.

So, remove references to WScript and you should find you’re good to go.

Update: Macro Scheduler 12 (currently in beta) ships with a built-in WScript object which implements the Echo and Sleep functions. This means that Wscript.Echo and WScript.Sleep functions will continue to work and will not need to be removed to make the .vbs work in Macro Scheduler.

February 18, 2010

February 17, 2010

And The Winner Is …

Filed under: Uncategorized — Marcus Tettmar @ 11:44 am

Thanks to everyone who entered our T-Shirt design competition. I’ve really enjoyed seeing all the entries and it has been very difficult to pick a winner. All entries are excellent in their own right and there are some great slogans, creative designs and novel concepts.

I have a number of favourite designs and, personally, I found it very hard to choose an outright winner. But the consensus amongst all the judges was for this one:

includekitchensink

We all like the way this conveys the right message in a simple, elegant way. Ok, some die-hard Macro Scheduler techies pointed out that the syntax isn’t Macro Scheduler syntax. But I don’t think that matters (the syntax used is recognisable and we could change the syntax and the message and concept would remain the same).

So, congratulations to Meryl for winning an Amazon Kindle!

Commiserations to everyone else and I’m really sorry there isn’t a truck full of Kindles to give away, or I’d be dolling them out, because I really liked a lot of these entries.

I’ve posted a few of the entries for sale on the MJT Net Zazzle store.  I wanted to post more, but Zazzle wouldn’t give me the “Post for Sale” option on them.  No idea why.  If yours is one of them, and you’d like it added to the store, then maybe you need to edit something.  Let me know if you figure it out.

February 16, 2010

Seeking Industry Partners

Filed under: General — Marcus Tettmar @ 10:24 am

Are you a contractor, consultant, freelancer or value added reseller who knows and uses Macro Scheduler and works in a specific industry, like Health Care, Education or Manufacturing? If you are I’d like to hear from you.

I’m looking at opportunities for Macro Scheduler in vertical markets and would like to find people with industry experience who can add value and help us promote and support Macro Scheduler in their sector. We need help identifying the key systems and applications used in these markets and creating macros and solutions for them using Macro Scheduler.

It doesn’t really matter what industry you work in. Whatever your vertical market, if you’re a Macro Scheduler user with industry knowledge and the flexibility to explore opportunities, please get in touch.

February 5, 2010

FTP Uploader – Upload Files From Explorer

Filed under: Announcements, General — Marcus Tettmar @ 5:03 pm

Phil Pendlebury has written a really handy little tool for quickly uploading files from Windows Explorer, and he’s built it using Macro Scheduler.

With his FTP Uploader tool installed you can right click on any file and select Send To->FTP Uploader to quickly upload it to any FTP site.

It will remember the FTP server settings for you and you can choose which FTP settings to use. If the uploaded file has a public web URL the tool will also create the URL for you and put it on the clipboard. Handy for sending people links to file, or uploading images and other files for use in forums.

FTP Uploader

You can download the tool and get the source code here.

I’m often uploading files to our FTP server to send to people, instead of relying on Email attachments. This tool will make short shrift of that. Thanks Phil!

February 1, 2010

Amazon Kindle T-Shirt Competition Now Closed

Filed under: Announcements — Marcus Tettmar @ 10:02 am

The T-Shirt competition is now closed. Many thanks for all your creative contributions. We will now get our heads together, look through the entries and decide on a winner. Will aim to announce a winner by 15th Feb.

January 29, 2010

Running Macro Scheduler Macros over the Web Via PHP

Filed under: Automation, General, Scripting, Web/Tech — Marcus Tettmar @ 9:31 am

Here’s a quick and simple proof of concept for running Macro Scheduler macros via the web and having their output displayed in the user’s browser:

Running Macro Scheduler Macros Over the Web Via PHP

The screenshot shows the PHP script, Macro Scheduler script and Internet Explorer being used to run the macro.

1) If you don’t already have a Windows based web server with PHP running, download and install WAMPServer. It’s easy.

2) Create a simple PHP script which takes an EXE name as a parameter and any parameters you want to pass to it. The following script will run EXEs that are in the c:\wamp\ folder, passing in any parameters provided and will dispay the EXEs output.

<?php
$exe = $_GET['exe'];

$dir = "c:\\wamp\\";

$parms = "";
foreach($_GET as $key=>$val) {
  $parms .= "/$key=$val ";
}

echo shell_exec("\"$dir$exe\" $parms");
?>

3) PHP’s safemode must be disabled for this script to work.

4) Create a Macro Scheduler macro and use SOWrite or SOWriteLn to output information. Compile it with the “Create Console App” option checked. Compile the EXE (or copy it) to the c:\wamp\ folder.

5) Now the macro can be executed via the web using http://servername/runmacro.php?exe=my.exe&parm1=value&etc=… which could be a link or entered into the browser directly.

6) Consider adding further security to the script to prevent anyone running any EXE on your server, or putting it in a password protected folder. I’ll leave that to you.

Macro Scheduler Enterprise comes with the msNet Remote Controller which includes a CGI module for running Macro Scheduler macros via web servers.

January 28, 2010

Force DBQuery to Read CSV Columns as Text

Filed under: Scripting — Marcus Tettmar @ 1:04 pm

In More on Reading and Writing CSV Files and various other posts I have demonstrated how CSV data can be read via a SQL SELECT statement using DBQuery.

In order to do this we used an ADO connection string in the DBConnect line:

Let>ConStr=Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\My Documents;Extended Properties='text;HDR=NO;FMT=Delimited'
DBConnect>ConStr,dbH

“Proper” CSV files use the double quote character to delimit strings. But there are many CSV files that do not contain these delimiters. When string delimiters aren’t used this should normally mean that the field is numeric, but that may not always be the case. So ADO sometimes has to take a guess as to whether a column is a string or a number. By default it does this by looking at the first 8 rows of data. This may not always be enough.

Watch what happens if we try to read in this file, which contains IP addresses:

abc.pluto.server.com,18.140.1.2
zxy.saturn.server.com,18.120.2.1
fyg.pluto.server.com,18.5.6.2

We’ll read it in with:

DBQuery>dbH,SELECT * FROM servers.csv,fields,num_recs,num_fields

Something weird happens. Look in the watch list and you’ll see the IP addresses have become:

18.1401
18.1202
18.562

ADO has decided that the IP addresses are numbers. It didn’t see any quote marks and after analysing the rows decided they are meant to be numbers. Bonus points go to anyone who can tell me why it has transformed the numbers in that way.

As mentioned before, ADO looks at the first 8 rows. If more of those 8 are more obviously strings, or contain string delimiters, it will treat them as strings. Try delimiting just one row of the above three. You’ll still get numbers. Delimit two and the problem is solved. Where the data type is mixed it will choose the type of the majority.

But we can’t go editing the CSV files to correct them.

What we can do is use a Schema.ini file. Using a Schema.ini file we can tell ADO what data types should be used for each column. So for our Servers.csv example above we could make a Schema.ini file as follows:

[Servers.csv]
Col1=ServerName Text
Col2=IPAddress Text

This file should be in the same folder as the CSV file.

Now, when we run our query we get the correct values, because we’ve forced ADO to treat the columns as text. Another advantage of this is that we have given our columns names, which is useful because our file doesn’t have a header column. This means we could set the Fieldnames parameter of our DBQuery line to 1 to return our array using the field names.

For more information on Schema.ini options for text files see:
http://msdn.microsoft.com/en-us/library/ms709353(VS.85).aspx

Most of the time you’ll probably be working with CSV files that you know about, so manually creating a schema.ini file once is no issue. But you could have the macro create it for you using WriteLn and/or EditIniFile.

What if your macro needs to read in a CSV file and you don’t already know how many fields there are, but you want to force everything to text? Well, how about doing this:

//Create schema.ini file
DBQuery>dbH,select * from servers.csv,fields,num_recs,num_fields,0
WriteLn>%SCRIPT_DIR%\schema.ini,res,[servers.csv]
Let>k=0
Repeat>k
  Let>k=k+1
  EditIniFile>%SCRIPT_DIR%\schema.ini,servers.csv,Col%k%,Col%k% Text
Until>k=num_fields

//now requery using schema.ini file
DBQuery>dbH,select * from servers.csv,fields,num_recs,num_fields,1
...

So this code uses a DBQuery to get the column count, and creates a schema.ini with each column called Coln where n is the column number and setting it to Text.


Side note: There’s another option called MaxScanRows which is supposed to help by telling ADO how many rows to scan, so that instead of looking at only 8 rows you can tell it to look at more, or less. According to the docs setting it to zero will cause it to scan all rows. Given that in our IP address experiment it took the IP addresses as numbers and we only had 3 which is less than the default 8 rows, I would have expected that setting MaxScanRows to 0 would make no difference. In fact it causes the IP addresses to come back as Text. So it seems to solve our initial problem., but I’m not sure why. Googling MaxScanRows reveals a number of forum and news group posts where others have had problems and there seems to be some confusion over exactly what it does. If we use MaxScanRows without ColNameHeader it also causes ADO to see the first line as a header line. And then setting ColNameHeader to false, while ensuring the first line is not seen as a header, brings back the original problem, where the IP addresses are converted to numbers. All seems a bit strange. Hence my preference for explicitly setting the data type of each column.

January 27, 2010

Why Does My Script “Hang” and Never Continue?

Filed under: Automation — Marcus Tettmar @ 9:47 am

This is a variation of a question we get regularly. Usually it turns out that the script is waiting on a WaitWindowOpen line because of a typo in the window title.

WaitWindowOpen, given a window title, will cause the script to wait until a window with that title exists.

If you misspell the window title WaitWindowOpen will wait forever, because a matching window will never appear.

Rather than rely on your typing, you can select the window title from a drop down list. With the window you want to wait for open on the screen edit your WaitWindowOpen line in the Code Builder by right clicking on it and selecting “Edit in Code Builder”. Now, select the window title from the drop down box.

Remember you can also do a sub-string match using the asterisk:

WaitWindowOpen>Notepad*

This works for all window functions and will match the first window found that contains the given text (regardless of case). So the above will match “Untitled – Notepad” as well as something like “My Notepad – MyFile.txt”. It will stop at the first one found, so don’t be too general and try to find something unique.

More advanced users might be interested to know that we’re adding the ability to use Regular Expressions in the window functions for version 12.