Scripting Problem (Virtual Server-Related)

Hi, I’m not very experienced with VBScript, so please forgive me. I have a simple script to discard undo disks on a virtual machine - here it is with hard-coded values, and this works fine using cscript:

Set vs = CreateObject(“VirtualServer.Application”, “DEXAE17260”)
Set vm = vs.FindVirtualMachine(“Trunk Build”)
vm.DiscardUndoDisks()

I moved this into a FinalBuilder Run Script action, in the OnExecute tab, this time using a couple of Project variables (VirtualServer and VirtualMachine):

Set vs = CreateObject(“VirtualServer.Application”, VirtualServer)
Set vm = vs.FindVirtualMachine(VirtualMachine)
vm.DiscardUndoDisks()

When I execute the FinalBuilder project, I get a ‘Runtime Error’ Just-In-Time Debugging dialog, and the option to debug using VS.NET 2003. When I fire up VS.NET, the ‘Set vm = …’ line is highlighted, and I get an ‘unknown exception’ dialog.

If I change the script in FinalBuilder to use hardcoded values for VirtualMachine and VirtualPC (so that it matches the original script), the same errors occur.

Finally, if I create an Execute Program action to execute cscript with the .VBS file (with the hard-coded values), all is well!!! Has anybody got any idea what I’m doing wrong? Or does anybody have any other ideas on how I can automate discarding my undo disks using Microsoft Virtual Server?

Thanks in advance,


Matt

Hi Matt,

Sorry, this is a known issue with running script from FinalBuilder and using Virtual Server ActiveX objects. It’s to do with the threading model when FB co-inits.

Anyway… you’ll either have to execute cscript or use the command line utility of Virtual Server (not sure if it supports the DiscardUndoDisks option though). If you’re going to use cscript, maybe you could generate the .vbs file using the create text file action (that way you don’t have to hard code the values).

hth.
.t8

Thanks for the info, Tate. Luckily I found out how to pass arguments into cscript, so it’s not too much of a problem now.

Hi Matt,

There’s actually an undocumented workaround for this (which is how the Virtual Server actions get around it.) This code should work:

Set vs = CreateObject(“VirtualServer.Application”, VirtualServer)
SetImpersonationLevel(vs)
Set vm = vs.FindVirtualMachine(VirtualMachine)
SetImpersonationLevel(vm)
vm.DiscardUndoDisks()


The SetImpersonationLevel call sets the Impersonate level on the ActiveX objects, which Virtual Server needs in order to function properly.

We also have a “Discard Undo Disks” action on our to-do list.

Regards,


Angus

That’s great, Angus - works a treat.

Many thanks,


Matt