Showing posts with label virtualpc. Show all posts
Showing posts with label virtualpc. Show all posts

Friday, February 24, 2006

WMI: Using WMI to detect machines running under Microsoft Virtual Server 2005

There’s probably quite a few situations where it would be useful to be able to programmatically detect if a particular OS is running under Virtual Server/Virtual PC or not. In my case, I was working at a new customer site; the sysadmin responsible for the site was out of town/unreachable, there was no documentation, and the only thing I had to go on was that the OS I needed to look at was running under Virtual Server.

So in working on my inventory script, I remembered seeing that in the output, some of the machines on my network had a model type of “Virtual Machine”. When I originally saw this, I didn’t give too much thought to it, but now, being in a situation where it would come in handy, I was immediately reminded of how useful this is.

After skimming through the script for a bit, I found what I needed and saw how/why the detection was working. Specifically the Win32_ComputerSystem class, which the WMI SDK says “represents a computer operating system in a Windows environment.” Contains a string called “Model”, which is a “Product name that a manufacturer gives to a computer.” Apparently, when the machine is working under Virtual Server 2005 or Virtual PC, the reported model type is “Virtual Machine”.

Okay, so great. This was really convenient, and helped me to solve my problem. So posted below you’ll see some code to do the detection. Also, after I did this I realized that Ben, over at the “Virtual PC Guy’s WebLogalready posted a similar script. His works a bit differently, which I’ll explain… He uses the Win32_BaseBoard class – which we know “represents a baseboard, which is also known as a motherboard or system board". And we can see he is looking at objItem.Manufacturer – a string that, again according to the SDK, represents the “Name of the organization responsible for producing the physical element.” Which is just to say, that he’s getting “Microsoft Corporation” from it, and he knows that any motherboards called “Microsoft Corporation”, are going to be Virtual Machines.

So his script actually looks pretty similar to mine. The only notable different is that he’s talking to a different class. But it’s neat, and useful... and there’s always more than one way to skin a cat! Have fun.

strComputer = "computername"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)

For Each objItem in colItems
strModel = objItem.Model
If strModel = "Virtual Machine" Then
wscript.echo "This is a virtual machine!"
else
wscript.echo "This is NOT a Virtual Machine"
End if
Next

Tuesday, June 14, 2005

Virtual PC: Using Differencing disks to role-back to a previous state

If you use Microsoft’s Virtual PC for anything, you should check out the Differencing Disks feature. Over the past few months, I’ve been making a effort to start leveraging Virtual PC as much as possible (side-note, I need more RAM in my main system), and the one of the features that I like most is the differencing disks feature!

Think of it like this… you have take a read-only base virtual hard disk (.VHD) image that you’ve built, running 2003 server for instance, and then you add any changes you make to a secondary, or child .VHD file called the differencing disk. You can then go back and add subsequent differencing disks off of that main base image for different types of services. In other words, you can create multiple points in time giving you the ability to easily role-back to a previous state.

One of the most effective ways that we’re using Virtual PC right now is in reproducing customer environments for testing, and the differencing disks feature goes a long way to making testing and documentation both easier and more comprehensive than was previously possible.

To add a differencing disk using Virtual PC 2004, SP1 just do the following:

Open Virtual PC, and select an instance, click “settings”. Next… hard disk 1 -> Virtual Disk Wizard ->Create a new Virtual disk -> A virtual hard drive -> Specify location -> Differencing -> Select the parent virtual disk

Managing your Virtual PC images is still a little more manual than it could be when compared to the Snapshot Manager in VMWare Workstation. For instance, I end up creating.TXT files in my Virtual PC directory structure to remind me what each .VHD is for, but Virtual PC certainly does provide for the basic necessities in terms of being able to easily role-back to a previous state.