01 December 2005

Registering VPCs

Here's a quick and easy script to register all the vpcs in a given folder.

Caveats: For this to work, it must be in the same folder as the virtual pc settings files (xxx.vmc). It also works better if VirtualPC has already been started.

Option Explicit
Dim oFSO, oShellDim sVPCPath, sImage, sVM, sVPC, sCmd, sExtDim f, f1, fc

'Get Absolute Path

Set oFSO = Createobject("scripting.FilesystemObject")
sVPCPath = oFSO.GetAbsolutePathName("")

'Start Virtual PC

Set oShell = CreateObject("WScript.Shell")
sVPC = Chr(34) & "c:\program files\microsoft virtual pc\virtual pc.exe" & Chr(34)
oShell.Run (sVPC & " -quiet")

'Build list of vmc files and register them

Set f = ofso.GetFolder(sVPCPath)
Set fc = f.Files
For Each f1 in fc
sExt = oFSO.GetExtensionName(f1)
If sExt = "vmc" Then
sCmd = sVPC & "-registervm " & Chr(34) & sVPCPath & "\" & f1.Name & Chr(34) oShell.Run (sCMD)
sCmd = ""
End If

WScript.Echo ("All vpcs registered")

No comments: