Create and Delete Virtual Machines The Script Way

Category:
System/API
Type:
Snippets
Difficulty:
Intermediate
Author:
Anonymous

Version Compatibility: Visual Basic 6, Visual Basic Script

More information:
You can use VBScript to create and delete MS Virutal Machines. The CreateVirtualMachine function takes two arguments, the name of the new VM and the path where the config file should be created. Optionally, you can pass NULL or an empty string in the first argument, which in turn requires the second argument to be the physical path to a new config file that will be used to create the new VM. This function returns a VMVirtualMachine object instance of your new VM. The DeleteVirtualMachine function only takes one argument, an instance of the VM object. Keep in mind, only a stopped VM can be deleted.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: