Script Tips

Getting to Know AutoIt

Check out this alternative scripting language with a lot to offer.

While VBScript is by far the most popular scripting language on the street, it is arguably neither the best nor most capable of the languages out there. I'm going to take a couple of columns here to discuss alternative languages to provide a brief overview of what they have to offer you. Namely: AutoIt, KiXtart and PowerShell.

Let's start with AutoIt, which has been around since 1999 and has grown a dedicated following of users. Written by Jonathan Bennett and a handful of other valued contributors, AutoIt has evolved into a very capable scripting language. As you might expect, AutoIt is freeware. For some reason I've heard it misstated that AutoIt is open source more than once, but it is not. It is however regularly updated and supported by its very dedicated community.

A "basic-like" scripting language, AutoIt focuses on the automating the Windows GUI. It was initially designed for PC rollouts and the automation of software installations, but it has evolved far beyond that -- particularly with the latest version 3 release. AutoIt requires only a small executable to process scripts (so no real "installation" is necessary) and it supports systems back to Windows 95. While some who may not have seen it in some time may still think of it as a more capable SendKeys replacement, you can do much more with this version today.

With AutoIt you can address almost any form control (like text boxes, labels, buttons, listviews, treeviews, etc.). AutoIt lets you grab hold of these form elements and do things such as select, click, enable, disable, read, modify, etc. This really gives you some powerful control not found in any other scripting language. You can simulate keystrokes and mouse movements to automate most anything you might do manually. One thing that had been lacking from AutoIt for some time now is support for COM. The recent addition of COM support now makes AutoIt a very good contender for an all-purpose language.

As a scripting language it offers a long list of built-in functions and, naturally, you can write custom functions as well. A very cool thing about AutoIt is that if you think this all sounds great, but you don't want to lean a new scripting language (even though it's very simple to learn, similar to KiXtart) it also offers a DLL version of its functions that may be used with any scripting language that supports COM. This means that you may use its many cool functions for automation and manipulation of windows from within the language you are currently familiar with, like VBScript or KiXtart.

For example, AutoIt lets you move the mouse pointer to a desired X/Y coordinate with its MouseMove function like so:

MouseMove(1,1)

If you register the AutoItX DLL that comes with AutoIt on your computer (on any computer you intend to run the script), you can use this same function within VBScript, like so:

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
oAutoIt.MouseMove 1, 1

Tech Help—Just An
E-Mail Away

Got a Windows, Exchange or virtualization question or need troubleshooting help? Or maybe you want a better explanation than provided in the manuals? Describe your dilemma in an e-mail to the MCPmag.com editors at [email protected]; the best questions get answered in this column and garner the questioner with a nifty Redmond T-shirt.

When you send your questions, please include your full first and last name, location, certifications (if any) with your message. (If you prefer to remain anonymous, specify this in your message, but submit the requested information for verification purposes.)

For more information on AutoIt, including some great documentation and sample scripts to show off its capabilities, visit http://www.autoitscript.com/autoit3 or http://www.adminscripteditor.com/langhome.asp?l=a.

Have something good or bad to say about AutoIt? Please comment on this article and share your views!

Mailbag
Bob: The script in your "Computer Name Targeting" column came at a time when I was thinking about how I could build a dynamic list of computers on my networks. I like your idea and want to extend the SQL script line to filter only names with "REG" in them. I have many things I need to do only with our register computers. I tried the SQL commands "Like" and "Contains" but neither of them worked. What sort of syntax could I use with this script to limit the computer names returned?
-- Ron

Ron, I think the syntax right there is pretty limited; I would just get all the computer names and look in the string for "REG". Take a look at http://www.adminscripteditor.com/editor/adsiwizard/; it pretty much writes the code for you...

Set oCn = CreateObject("ADODB.Connection")
Set oCmd = CreateObject("ADODB.Command")
oCn.Provider = "ADsDSOObject"
oCn.Open "Active Directory Provider"
Set oCmd.ActiveConnection = oCn
oCmd.Properties("Page Size") = 1000
oCmd.Properties("Searchscope") = 2
oCmd.CommandText = "SELECT name
FROM 'LDAP://appdeploy/CN=Computers,
DC=appdeploy,DC=local'
WHERE objectCategory='computer'"
Set oRS = oCmd.Execute
Do Until oRS.EOF
If InStr(UCase(oRS.Fields(0).Value), "REG") Then
WScript.Echo oRS.Fields(0).Value
End If
oRS.MoveNext
Loop

Best of luck! -- Bob

About the Author

Bob Kelly is president and co-founder of AdminScriptEditor.com, home to an integrated suite of scripting tools and a shared library of scripts and language help. He has authored books on scripting and desktop administration and several white papers. Bob also owns and operates AppDeploy.com, where he writes and produces videos on topics related to software deployment.

comments powered by Disqus
Most   Popular