Click Here to Install Silverlight.*
United StatesChange|All Microsoft Sites
Microsoft TechNet*
Search Microsoft.com for:
|TechCenters|Downloads|TechNet Program|Subscriptions|Security Bulletins|Archive
Search for

Microsoft Agent: Teach Your Scripts to Talk

Microsoft Agent

When you think about some of the things you’ve said to your computer, you might consider it a blessing that computers don’t talk back (or have the ability to throw things). And yet, as a script writer there are probably times when you’d find it useful to be able to incorporate a little audio feedback – and a little animation – into your code. For example, visually-impaired users might appreciate having logon script feedback provided via the spoken word as opposed to hard-to-read visual feedback provided in tiny dialog boxes. Novice users might appreciate voiced explanations rather than cryptic message boxes or command window text that scrolls by faster than the human eye can read. And – gasp! – sometimes you just might find a talking head more fun than yet another dialog box that people automatically click without reading.

If you’ve ever thought to yourself, “I wish my script could just tell everyone what’s going on,” you’re in luck: the Microsoft Agent technology (yes, the same technology that brought us Clippy the Paperclip and Rover, the dog who … helps … you when you want to search your hard drive) is fully scriptable. We don’t know if you’ll ever have the need – or the desire – to include a Microsoft Agent in your scripts, but just in case, we’re here to show you how.

Note. This article assumes you have already set up Microsoft Agent on your computer. The Microsoft Agent technology comes pre-installed on Windows 2000 and Windows XP; however, on Windows XP you’ll need to install a speech engine and the SAPI 4.0 runtime. For more information, see the Microsoft Agent home page.

*
On This Page
Now You See It … Or Do You?Now You See It … Or Do You?
Programming Microsoft AgentProgramming Microsoft Agent
Bossing Your Character AroundBossing Your Character Around
Using Microsoft Agent in a System Administration ScriptUsing Microsoft Agent in a System Administration Script
Is That All There Is?Is That All There Is?

Now You See It … Or Do You?

Although the idea of displaying and controlling talking characters sounds extremely complicated, programming Microsoft Agent is actually pretty straightforward. Want your character to say hello? Then use a line of code similar to this:

objCharacter.Speak "Hello."

Want your character to look surprised? Then use a line of code similar to this:

objCharacter.Play "Surprised"

For the most part, that’s all there is to it. In fact, the only tricky part about scripting with Microsoft Agent is getting your character to appear onscreen and then having him or her (or it) stick around long enough to do whatever they were programmed to do. This is because Microsoft Agent code runs asynchronously; you initialize the Agent and then – unless you take the proper steps, which we’ll explain shortly – your character runs totally independent of any other code in your script. There’s an advantage to that: that way, your character doesn’t get in the way of the rest of your script (for example, displaying an Agent won’t slow down a script that’s busy taking a hardware or software inventory). But there’s also a disadvantage to this: if the rest of your code runs faster than your Agent code, the script might complete before your Agent even appears.

We know that’s a bit confusing, so let’s just show you what we mean. Here’s a simple script that is supposed to display the Merlin character. As soon as he appears on screen, Merlin is supposed to knock on your monitor to get your attention, say hello and goodbye, and then disappear:

strAgentName = "Merlin"
strAgentPath = "C:\Windows\Msagent\Chars\" & strAgentName & ".acs"
Set objAgent = CreateObject("Agent.Control.2")

objAgent.Connected = TRUE
objAgent.Characters.Load strAgentName, strAgentPath
Set objCharacter = objAgent.Characters.Character(strAgentName)

objCharacter.Show
objCharacter.Play "GetAttention"
objCharacter.Speak "Hello, how are you?"
objCharacter.Speak "I'm going now. Goodbye."
objCharacter.Hide

Like we said, that’s what this script is supposed to do. But what really happens when you run this script? Nothing. Merlin doesn’t even appear onscreen, let alone knock on the monitor or say anything.

Before you ask, the code for controlling Merlin is correct; the problem lies in the timing of that code. When the script runs, it executes the lines in order, and executes them as quickly as possible. Among other things, that means it sends the command to display (show) Merlin and then, instead of waiting for Merlin to actually make his appearance, begins executing the other lines of code. That’s fine, except that it takes Merlin a second or two to initialize and actually appear onscreen. By the time Merlin is ready to make his appearance, the script engine has executed the last line of the script. Because the last line of code has been executed, the script automatically terminates. And as soon as the script terminates, agentsrv.exe (the process responsible for running Microsoft Agent) terminates as well. The script simply runs too fast and the Agent server can never catch up. As a result, Merlin never shows up.

If you want to test this, try running the modified script below. In this script, we’ve inserted an Echo statement right after we issue the command to make Merlin appear onscreen. If you run this script using Wscript (rather than Cscript) this brings up a message box, which in effect pauses the script. As long as you don’t click OK right away, you’ll actually see Merlin. As soon as you click OK and dismiss the message box, however, Merlin will disappear. Why? The same issue we ran into before: the remaining lines of code are executed too quickly; Merlin never has a chance to respond to a command before the script ends. (If you run this script using Cscript the statement will echo to the command window and you still won’t even see Merlin.)

strAgentName = "Merlin"
strAgentPath = "C:\Windows\Msagent\Chars\" & strAgentName & ".acs"
Set objAgent = CreateObject("Agent.Control.2")

objAgent.Connected = TRUE
objAgent.Characters.Load strAgentName, strAgentPath
Set objCharacter = objAgent.Characters.Character(strAgentName)

objCharacter.Show

Wscript.Echo "Waiting on Merlin."

objCharacter.Play "GetAttention"
objCharacter.Speak "Hello, how are you?"
objCharacter.Speak "I'm going now. Goodbye."
objCharacter.Hide

Try the script a few times, sometimes clicking the message box right away, other times waiting a bit before dismissing the message box. You’ll see what we mean.

Obviously this is a bit of a problem; talking characters are typically more useful and more interesting when they actually appear on screen and talk. Fortunately, there are at least two ways to work around this problem. We’ll show you a very simple method for now, then demonstrate a slightly more complicated (but more versatile) method later in this article.

As you might have noticed, to make Merlin appear on screen we simply call the Show method. After Merlin appears he’ll then stay onscreen until one of two things happens: either the script ends or we call the Hide method. It turns out that the Hide method is the key: to keep Merlin around until we’re ready to get rid of him, we just need to make sure that the script never ends, at least not until we’ve called the Hide method.

Probably the easiest way to do this is to add these three lines of code to the end of your script:

Do While objCharacter.Visible = TRUE
    Wscript.Sleep 250
Loop

What we’ve done here is create a loop that runs as long as the Visible property of our agent is True; that is, as long as the character is on screen. If Merlin is on screen, the script pauses for a quarter of a second (Wscript.Sleep 250), then loops around and checks to see if Merlin is still visible. This continues until Merlin is no longer onscreen; when Merlin is no longer visible, the Visible property will be False, and the script will break out of the loop. Because the loop happens to be the last few lines of code in the script, that also means that the script will terminate the moment we dismiss Merlin.

Oh, right: In case you’re wondering, this is the line of code that dismisses Merlin:

objCharacter.Hide

Still confused? Whenever a Microsoft Agent script (or any other script) runs, each and every line of code is executed in order, and as quickly as possible. Most of the code in this script happens to be commands to make Merlin do something. Those commands are stored in a queue and Merlin will execute them in order. Those commands were queued up in our previous script as well, but the script ended before Merlin could run any of them. In other words, the script would run through each line of code, stashing Merlin commands in the queue. In turn, Merlin would carry out those commands in the order in which they were queued. However, the script reached the last line of code faster than Merlin could empty his command queue. When the last line of code in a script is executed the script automatically ends. And the end of the script spells curtains for Merlin as well.

Now we’ve configured the script so that it won’t end until Merlin processes the Hide command from the queue. Because Hide is the very last command we issue to Merlin, Merlin will carry out all the other commands in his command queue before hiding himself, and then the script will end.

Here’s a complete script that will display Merlin, make him knock on your monitor to get your attention, have him say hello and goodbye, and then make him disappear:

strAgentName = "Merlin"
strAgentPath = "C:\Windows\Msagent\Chars\" & strAgentName & ".acs"
Set objAgent = CreateObject("Agent.Control.2")

objAgent.Connected = TRUE
objAgent.Characters.Load strAgentName, strAgentPath
Set objCharacter = objAgent.Characters.Character(strAgentName)

objCharacter.Show
objCharacter.Play "GetAttention"
objCharacter.Speak "Hello, how are you?"
objCharacter.Speak "I'm going now. Goodbye."
objCharacter.Hide

Do While objCharacter.Visible = TRUE
    Wscript.Sleep 250
Loop

We know, we know. But our intention here isn’t to scare you off before you even get started. It’s just that Microsoft Agent doesn’t work like other scripting technologies. If you have a script that uses WMI, the script will dutifully wait for all the WMI code to execute before it continues; the same is true for ADSI, CDO, WSH, or any other scripting acronym you might throw out. That’s not the case with Microsoft Agent, however, so you need to keep that in mind or you’ll probably never get an Agent script to work the way you want it to. But trust us: from here on it’s a piece of cake.

Programming Microsoft Agent

Let’s start from the beginning. We’ll take a quick look at the code that instantiates Microsoft Agent, loads a character for us, and then displays that character on the screen:

strAgentName = "Merlin"
strAgentPath = "C:\Windows\Msagent\Chars\" & strAgentName & ".acs"
Set objAgent = CreateObject("Agent.Control.2")

objAgent.Connected = TRUE
objAgent.Characters.Load strAgentName, strAgentPath
Set objCharacter = objAgent.Characters.Character(strAgentName)

objCharacter.Show

After defining a pair of variables, the script creates an instance of the Microsoft Agent server and connects to that instance. The script then loads the character whose name (strAgentName) and file path (strAgentPath) we specified in the first two lines of the script. With the character loaded, the script creates an instance of the Character object, an instance that corresponds to the character just loaded. The script then shows our character using this line of code:

objCharacter.Show

That’s all there is to it; in fact, you’ll likely be able use this boilerplate code as-is in most of your scripts. About the only thing you might have to change is the name of the character (assuming you want to use a character other than Merlin) and, possibly, the path to the .acs files (necessary only if those files aren’t found in C:\Windows\Msagent\Chars). Other than that, you can just copy and paste the boilerplate code into every script you write that uses Microsoft Agent.

Note. We’ve chosen Merlin as our sample character because Merlin ships with and is installed with Windows. However, there are other characters available for use, including three Microsoft characters that can be downloaded for free: Peedy the Parrot; Genie the genie; and Robby the Robot. For more information, see the Microsoft Agent home page.

By default, characters have an “entrance animation” they use whenever you call the Show method; with Merlin, for example, his hat appears and then he sort of falls down from inside the hat. If you’d rather just have the character appear without the dramatic entrance animation, then simply set the optional Fast parameter of the Show method to TRUE:

objCharacter.Show TRUE

Bossing Your Character Around

After we get Merlin to appear on screen we can start ordering him around. For now, we’ll assume that there are six things you can do with a character after you call the Show method:

Have the character say something (using the Speak method).

Have the character think something (using the Think method).

Have the character do something, such as look happy, look confused, or wave goodbye (using the Play method).

Have the character point to something (using the GestureAt method).

Have the character move to another part of the screen (using the MoveTo method).

Dismiss the character (using the Hide method).

Let’s take a look at a script that carries out all of these actions:

strAgentName = "Merlin"
strAgentPath = "c:\windows\msagent\chars\" & strAgentName & ".acs"
Set objAgent = CreateObject("Agent.Control.2")

objAgent.Connected = TRUE
objAgent.Characters.Load strAgentName, strAgentPath
Set objCharacter = objAgent.Characters.Character(strAgentName)

objCharacter.Show

objCharacter.Play "GetAttention"
objCharacter.Speak "Hello, how are you?"
objCharacter.Play "LookDown"
objCharacter.Think "Maybe I should move around a little ...."
objCharacter.MoveTo 500,400
objCharacter.Play "Pleased"
objCharacter.Speak "Goodbye."
objCharacter.Hide

Do While objCharacter.Visible = TRUE
    Wscript.Sleep 100
Loop

And now let’s look at each of these actions in a little more detail.

Making a character speak

Believe it or not, one of the simplest things you’ll ever do as a script writer is make a character speak: you simply call the Speak method followed by whatever it is you’d like the character to say. If you use this line of code:

objCharacter.Speak "Hello, how are you?"

You’ll end up seeing something like this, and hearing the spoken words to boot:

Microsoft Agent

By default, each time a character speaks, his or her words are accompanied by a word balloon. If you’d rather have the character speak without displaying the word balloon, then simply set the Balloon.Style property to 0:

objCharacter.Balloon.Style = 0

You’ll still hear Merlin’s voice, but you’ll no longer see the word balloon:

Microsoft Agent

Making a character think

Making a character think follows pretty much the same steps as making a character speak: you call the Think method followed by whatever you want the character to think. For example, this code instructs your character to think the thought, “Just a moment; I’m thinking.”

objCharacter.Think "Just a moment; I’m thinking."

When a character thinks, his or her thoughts appear in a word balloon only. The character does not appear to speak, and no sound is heard.

Microsoft Agent

Making a character do something

Each Microsoft Agent character comes with a set of animations that can be called using the Play method. For example, suppose you’d like your character to look sad. All you have to do is call the Sad animation:

objCharacter.Play "Sad"

Likewise, Merlin can signal an announcement by taking out and blowing a trumpet. To do that, call the Announce animation:

objCharacter.Play "Announce"
Microsoft Agent

The animations available to you vary depending on the character. (Animations are not generic, they’re hard-coded into each character.) A list of animations available for Merlin is shown in the following table.

Animation

Description

Acknowledge

Nods head

Alert

Straightens and raises eyebrows

Announce

Raises trumpet and plays

Blink

Blinks eyes

Confused

Scratches head

Congratulate

Displays trophy

Congratulate_2

Applauds

Decline

Raises hands and shakes head

DoMagic1

Raises magic wand

DoMagic2

Lowers wand, clouds appear

DontRecognize

Holds hand to ear

Explain

Extends arms to side

GestureDown

Gestures down

GestureLeft

Gestures to his left

GestureRight

Gestures to his right

GestureUp

Gestures up

GetAttention

Leans forward and knocks

GetAttentionContinued

Leaning forward, knocks again

GetAttentionReturn

Returns to neutral position

Hearing_1

Ears extend (looping animation)

Hearing_2

Tilts head left (looping animation)

Hearing_3

Turns head left (looping animation)

Hearing_4

Turns head right (looping animation)

Hide

Disappears under cap

Idle1_1

Takes breath

Idle1_2

Glances left and blinks

Idle1_3

Glances right

Idle1_4

Glances up to the right and blinks

Idle2_1

Looks at wand and blinks

Idle2_2

Holds hands and blinks

Idle3_1

Yawns

Idle3_2

Falls asleep (looping animation)

LookDown

Looks down

LookDownBlink

Blinks looking down

LookDownReturn

Returns to neutral position

LookLeft

Looks left

LookLeftBlink

Blinks looking left

LookLeftReturn

Returns to neutral position

LookRight

Looks right

LookRightBlink

Blinks looking right

LookRightReturn

Returns to neutral position

LookUp

Looks up

LookUpBlink

Blinks looking up

LookUpReturn

Returns to neutral position

MoveDown

Flies down

MoveLeft

Flies to his left

MoveRight

Flies to his right

MoveUp

Flies up

Pleased

Smiles and holds his hands together

Process

Stirs cauldron

Processing

Stirs cauldron (looping animation)

Read

Opens book, reads and looks up

ReadContinued

Reads and looks up

ReadReturn

Returns to neutral position

Reading

Reads (looping animation)

RestPose

Neutral position

Sad

Sad expression

Search

Looks into crystal ball

Searching

Looks into crystal ball (looping animation)

Show

Appears out of cap

StartListening

Puts hand to ear

StopListening

Puts hands over ear

Suggest

Displays light bulb

Surprised

Looks surprised

Think

Looks up with hand on chin

Thinking

Looks up with hand on chin (looping animation)

Uncertain

Leans forward and raises eyebrows

Wave

Waves

Write

Opens book, writes and looks up

WriteContinued

Writes and looks up

WriteReturn

Returns to neutral position

Writing

Writes (looping animation)

You can also use a script like this to retrieve the animations associated with a character:

strAgentName = "genie"
strAgentPath = "C:\WINDOWS\msagent\chars\" & strAgentName & ".acs"
Set objAgent = CreateObject("Agent.Control.2")

objAgent.Connected = TRUE
objAgent.Characters.Load strAgentName, strAgentPath
Set objCharacter = objAgent.Characters.Character(strAgentName)

For Each strName in objCharacter.AnimationNames
    Wscript.Echo strName
Next

Looping Animations. You might have noticed that several of the animations in the table are marked as being “looping” animations. A looping animation is an animation that runs until you specifically tell it to stop (by using the Stop method). For example, here’s a script that runs forever. Why? Because we called a looping animation (Searching) and did not explicitly stop it:

strAgentName = "Merlin"
strAgentPath = "C:\Windows\Msagent\Chars\" & strAgentName & ".acs"
Set objAgent = CreateObject("Agent.Control.2")

objAgent.Connected = TRUE
objAgent.Characters.Load strAgentName, strAgentPath
Set objCharacter = objAgent.Characters.Character(strAgentName)

objCharacter.Show
objCharacter.Speak "Please wait."
objCharacter.Play "Searching"
 
objCharacter.Hide

Do While objCharacter.Visible = True
    Wscript.Sleep 250
Loop

Note. You can stop the animation – and the script – by right-clicking Merlin and choosing Hide.

Here’s a modified script that uses the Stop method. After calling the Searching animation, we use Wscript.Sleep to pause the script for a few seconds; that’s to make sure the script actually has time to start the animation. We then use the Stop method to stop the animation and allow the script to finish:

strAgentName = "Merlin"
strAgentPath = "C:\Windows\Msagent\Chars\" & strAgentName & ".acs"
Set objAgent = CreateObject("Agent.Control.2")

objAgent.Connected = TRUE
objAgent.Characters.Load strAgentName, strAgentPath
Set objCharacter = objAgent.Characters.Character(strAgentName)

objCharacter.Show
objCharacter.Speak "Please wait."
objCharacter.Play "Searching"

Wscript.Sleep 10000
 
objCharacter.Stop

objCharacter.Hide

Do While objCharacter.Visible = True
    Wscript.Sleep 250
Loop

Making a character point

What about gestures, you ask? Good question. Sometimes you don’t want to play an animation; you simply want your character to point in a general direction. To do that you can call the GestureAt method, passing two parameters: the left position (in pixels) and the top position (also in pixels). These values will force the character to gesture in the approximate direction specified (the animation is not sophisticated enough to point to the exact pixel). Code like this will probably cause Merlin to point to the left side of the screen. (Why probably? The exact direction Merlin will gesture depends not only on the coordinates you enter but also on Merlin’s current screen position. To get the exact effect you want to achieve, you might have to experiment a little,)

objCharacter.GestureAt 0, 0

Code like this will cause Merlin to point to the right side of the screen:

objCharacter.GestureAt 800, 0
Microsoft Agent

To be honest, depending on Merlin position on the screen it was sometimes difficult to predict which way he would gesture. If you want to ensure that your character looks in a specific direction it’s a good idea to play an animation such as LookRight or LookLeft rather than relying on GestureAt.

Making a character move somewhere

You can use the MoveTo method to move your character around on the screen. MoveTo measures screen movement in pixels, with 0, 0 representing the left, top edge of the screen. To move a character to a position 200 pixels from the left of the screen and 600 pixels from the top of the screen, use code like this:

objCharacter.MoveTo 200, 600
Microsoft Agent

By default a character’s speed is set at 1000 milliseconds. To change the character’s speed, add a third parameter to the MoveTo method. To make the character move faster, add a number less than 1000; to make it move slower, add a number greater than 1000. For example, this line of code moves Merlin at approximately half his normal speed:

objCharacter.MoveTo 200, 600, 2000

By default, a built-in animation causes a character to move smoothly from one location to another. If you’d prefer to have a character suddenly disappear from one spot and then reappear in another, set the optional speed parameter to 0:

objCharacter.MoveTo 200, 600, 0

The MoveCause Property. If you’re looking for something a little crazy to do with a character (and, let’s face it, you wouldn’t have read this far if you weren’t), each character has a MoveCause property that indicates the cause behind the character’s last move. MoveCause returns one the values shown in the following table:

Value

Description

0

The character has not been moved.

1

The user moved the character.

2

Your application moved the character.

3

Another client application moved the character.

4

The Agent server moved the character to keep it onscreen after a screen resolution change.

Why is that cool? Well, here’s a simple little script that pops Merlin up on screen and has him ask people not to click on him and drag him around. The script then checks the value of the MoveCause property. If MoveCause is equal to 1, that means the user moved the character; Merlin, in turn, acts surprised and reminds the user, “Hey, I said don’t move me!” If the user doesn’t move Merlin, then Merlin says nothing. This script also makes use of the Request object, something we’ll discuss in the next section of this article.

strAgentName = "Merlin"
strAgentPath = "c:\windows\msagent\chars\" & strAgentName & ".acs"
Set objAgent = CreateObject("Agent.Control.2")

objAgent.Connected = TRUE
objAgent.Characters.Load strAgentName, strAgentPath
Set objCharacter = objAgent.Characters.Character(strAgentName)

objCharacter.Show
Set objRequest = objCharacter.Speak _
    ("Please don't click the mouse and drag me to a new location.")

Do While objRequest.Status > 0 
    Wscript.Sleep 500
Loop

If objCharacter.MoveCause = 1 Then
    objCharacter.Play "Surprised"
    objCharacter.Speak "Hey, I said don't move me!"
End If

objCharacter.Hide

Wscript.Sleep 3000

Do While objCharacter.Visible = True
    Wscript.Sleep 1000
Loop

To see how this works, run the script twice: one time dragging Merlin to a new location, the next time leaving him be.

Making a character disappear

As we noted earlier, you can make a character disappear simply by calling the Hide method:

objCharacter.Hide

Like the Show method, the Hide method also has an optional Fast parameter. By default, your character will play an exit animation when you call the Hide method; in Merlin’s case, he sort of rolls himself up into his hat and then disappears. If you’d prefer to have the character just disappear, without the exit animation, then set the Fast parameter to TRUE:

objCharacter.Hide TRUE

Using Microsoft Agent in a System Administration Script

Up to this point we’ve focused on showing you how to get a character to appear and then stick around long enough to do something interesting. Sometimes this might be enough; for example, you might want your character to pop up just long enough to say something like, “Please wait while we finish processing your logon script” and then disappear. At other times, however, you might want your character to stick around for the duration of the script. As we saw earlier, however, there’s a problem with that: how can we keep the character in synch with the script when the character runs on one thread and the rest of the script runs on another?

Perhaps the best way to do this is to make use of the Request object. Any time you call a character method, a Request object is created; this object includes a Status property that can tell you the current state of that method. If the Status of the request is 0, then the request is complete (for example, the animation has finished playing); if the request is greater than 0 (Status values range from 0 to 4) then the request is either in the queue, in progress, or has been interrupted. (For a complete explanation of the Request object and its status codes, see this portion of the Microsoft Agent SDK on MSDN.)

Using the Request object enables us to pause the script until a specified method has completed. For example, to ensure the Announce animation plays all the way to the finish, we can use code similar to this:

Set objRequest = objCharacter.Play("Announce")

Do While objRequest.Status > 0
    Wscript.Sleep 100
Loop

When we call the Play method, we simultaneously instantiate an instance of the Request object. In the next line of code, we create a Do While loop that checks the Status property. If Status is greater than 0, the script sleeps for 100 milliseconds, then loops around and checks the Status property again. If the Status is equal to 0, we exit the loop and continue with the next line of code.

By sprinkling these Do While loops throughout our script, we can do a reasonably good job of synchronizing the behavior of our character and the rest of our script.

For example, here’s a script that displays the Merlin character, then leaves Merlin onscreen as it retrieves (and echoes) information about the services installed on a computer:

strAgentName = "Merlin"
strAgentPath = "C:\Windows\Msagent\Chars\" & strAgentName & ".acs"
Set objAgent = CreateObject("Agent.Control.2")

objAgent.Connected = TRUE
objAgent.Characters.Load strAgentName, strAgentPath
Set objCharacter = objAgent.Characters.Character(strAgentName)

objCharacter.Show
Set objRequest = objCharacter.Play("Announce")

Do While objRequest.Status > 0
    Wscript.Sleep 100
Loop

Set objRequest = objCharacter.Speak _
    ("Please wait while we collect inventory information for your computer.")

Do While objRequest.Status > 0
    Wscript.Sleep 100
Loop

objCharacter.Play "Writing"

Wscript.Sleep 5000

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
    ("Select * From Win32_Service")

For Each objService in colServices
    Wscript.Echo objService.Name, objService.Status
Next

objCharacter.Stop

Set objRequest = objCharacter.Speak _
    ("We're done. Thank you for your patience.")

Do While objRequest.Status > 0
    Wscript.Sleep 100
Loop

objCharacter.Hide

Notice how we use the Request object to control the flow of the script. We begin by calling the Announce animation; we use the Request object to ensure that this animation completes before the script moves on. Next we have Merlin tell the user that we’re about to collect inventory information. Again, we use the Request object to make this pronouncement; this ensures that Merlin gets a chance to make his speech. We call the Writing animation (a looping animation), and then insert a 5-second pause (Wscript.Sleep 5000); we insert the pause because service information returns very quickly, and we want to make sure the animation has a chance to begin playing. If your script returns a lot of inventory-type information (and thus takes longer to run), you likely won’t need to insert a pause.

With our looping animation running, we now use WMI to retrieve service information. After this information has been gathered, we call the Stop method to stop our looping animation. We then have Merlin say goodbye, once again using the Request object to ensure that he has the chance to make his speech. And there you have it: an animation reasonably in synch with the rest of the script.

Is That All There Is?

Most likely you’ll master the basics of using Microsoft Agent in no time; after all, it really is that easy. But then what? Is that all there is: you make an Agent appear onscreen, the character says something, and then it’s all over?

Far from it; in fact, there are all sorts of other cool things you can do with Microsoft Agent. For example, you can display two or more Agents onscreen at the same time, and have them interact with one another. For that matter, you can even enable speech recognition and have the Agent interact with you: you can issue voice commands that the Agent will respond to. All of that lies well beyond the scope of this introductory article, but if there’s enough interest we’ll revisit these topics at a later date. In the meantime, you can get a complete list of Agent capabilities by checking out the Microsoft Agent SDK on MSDN.

Handy Hint: If you’re looking for a graphical utility that makes it easy to write Microsoft Agent scripts, take a look at MASH (Microsoft Agent Scripting Helper) available from http://www.bellcraft.com/mash.

Microsoft Agent
 

© 2008 Microsoft Corporation. All rights reserved. Terms of Use |Trademarks |Privacy Statement |Contact Us
Microsoft