GUI Scripts with KiXforms
Spice up your scripts with a graphical interface.
Message boxes and console windows will only get you so far. If you really want to take your scripts up a notch, a graphical interface can make a huge difference. Not only can you make your script easier for others to use, you can do more with it by taking advantage of the many ways you can display (and collect) information.
When many think of creating a graphical user interface for a script, they think Hypertext Application. An HTA allows you to create a client-side Web page capable of running your script code while taking advantage of the interface controls a Web page provides. This includes the ability to use images, combo boxes, text boxes, buttons, radio buttons and check boxes. These elements can make your script capable of much more than it could when limited to input and output from a simple console window and message box.
Tech Help—Just An
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
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.)
Microsoft provides some good resources for HTA at its HTA Developers Center. I do intend to talk more about HTA and how to take advantage of its capabilities in future articles, but what I will to do in the next couple of articles is introduce you to a very capable alternative: KiXforms.
KiXforms is a free DLL you can download and register on your system, which will allow you to use any script language that supports COM to generate forms with most of the controls you might expect from a full-blown application. This includes many controls not offered by HTA, such as tabs, treeviews and listviews.
You’ll find KiXforms at http://www.kixforms.org, along with some sample scripts that take some creative approaches to showing off its capabilities.
A very quick step-by-step to getting your system ready for KiXforms:
- Download KiXforms from http://www.kixforms.org/assets/index.htm.
- Extract the contents of the zip file and copy the file kixforms.dll to c:\windows\system32. (Note: there is also a nice little help file you’ll want to hold onto!)
- Register the KiXforms DLL by entering the following at the command prompt: Regsvr32.exe kixforms.dll.
At the site, you’ll also find a free tool called the KiXforms Designer, which helps you design forms using a WYSIWYG display. However, it generates KiXtart script code, not VBScript. Despite this, you will find it a helpful tool for designing forms (particularly for identifying desired positions and sizes for controls) and KiXtart is not so different from VBScript, that translating the code it generates is pretty straight forward.
Below is a very basic script that displays a simple "hello world" form. This is a very simple and self-explanatory script to help you see how KiXforms works with VBScript.
Set System = CreateObject("KiXtart.System")
Set Form1 = System.Form()
Form1.Size = System.Size(169, 125)
Form1.Text = "Demo"
Set Button1 = Form1.Controls.Button
Button1.Size = System.Size(75, 23)
Button1.Location = System.Point(43, 56)
Button1.Text = "Close"
Button1.OnClick = "Quit()"
Set Label1 = Form1.Controls.Label
Label1.Size = System.Size(137, 44)
Label1.Text = "Hello World!"
Label1.Location = System.Point(12, 9)
Form1.Visible = "True"
Do While Form1.Visible
Don’t worry, this is just the introduction. We’ll do something more interesting with KiXforms in the weeks to come!
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.