Step Up to Scripting with KIXforms
Adding a GUI to your scripting work with KiXforms, part 2.
It's been a while since we talked about creating a GUI for
working with scripts (and my editor says to blame him for the long respite).
Particularly, we talked about using KIXforms to do it and I showed you
a nifty sample to get you started down that road last
Let’s get into it by walking through the creation of
a simple dialog (see Fig. 1) The script contains a main form, an image
(known as a PictureBox), some text (known as a label) and a button. The
button is instructed to end the script. It's not much, but it's a very
good start to seeing just how KiXforms operates and how you can take advantage
of it in VBScript.
|Figure 1. Now, doesn't working with scripts in
this territory seem a bit more familiar?Using KiXforms you can make your scripts look much better than
the standard console window full of text.
First, you need to create an object variable that references
the KiXforms DLL. The Type Library name is “KiXtart.System,”
so begin by setting this object variable:
Set System = CreateObject("KiXtart.System")
KiXforms is processed from the top to the bottom of the script, so you
must specify any objects in the order they are needed. Therefore, start
by establishing the form that will hold the image, text and button. First,
set another object variable to create a reference to a form object. Then
set the size (height and width) and text (that appears as the window title)
for the form:
Set Form = System.Form()
Form.Height = 309
Form.Width = 281
Form.Text = "Welcome"
Now that you have a form, it's time to add text. Doing this is much the
same as how you create the form, but in addition to its size you must
also tell KiXforms where to place the text items. The location is specified
by indicating the number of pixels from the top of the form, and from
the left of the form:
Set Label = Form.Controls.Label
Label.Height = 38
Label.Width = 250
Label.Top = 199
Label.Left = 11
Label.Text = "Welcome to the network, by " &_
" using this system you agree to the " &_
" corporate policy for this network."
The same properties need to be set for the image, which is referred to
as a PictureBox. Additionally, you also specify a picture property that
identifies the path to the image you want to display:
Set PictureBox = Form.Controls.PictureBox
PictureBox.Height = 175
PictureBox.Width = 250
PictureBox.Top = 12
PictureBox.Left = 11
PictureBox.Picture = "c:\windows\winnt256.bmp"
Finally, specify the size, location and text for the button. Here, you'll
also set your first event. When the button is clicked, you'll want to
run a function called ExitScript. This is set as a string which is executed
when the event is triggered (in this case the OnClick event that happens
when someone clicks the button).
Set Button = Form.Controls.Button
Button.Height = 23
Button.Width = 75
Button.Top = 240
Button.Left = 100
Button.Text = "OK"
Button.OnClick = "ExitScript()"
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.)
With your form all laid out, you now need to get the script in a loop
where it will look for any events to be triggered. The script has called
out all the details of the form, so it is ready to show to the user. Therefore,
set the visible property to true and the form appears on the screen. Without
the Do/While loop you see below, the script would end and the user would
never catch sight of your nice form. So after setting the form to visible,
instruct the script to execute the events of the form as long as the form
Form.Visible = "True"
Do While Form.Visible
The DoEvents method runs as long as the script is visible and fires any
specified events for the script. In the case of this example, the only
event you've handled is the clicking of the button. When the button is
clicked, you have it running a function called ExitScripts; here's the
function to complete the script:
WScript.Echo "Exiting Script..."
This provides most of the structure you need to get started, and you
can get plenty of help from the help file provided along with the KiXforms
binary at http://www.kixforms.org.
In the next (and last) article in this short series on KiXforms, I’ll
cover some of the more advanced controls that you can’t get using
a traditional HTA graphical interface -- this is where the freely available
KiXforms really shines as a unique and powerful tool for your scripts.
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.