Sending custom parameters into virtual machines under Virtual Server

Sending custom parameters into virtual machines under Virtual Server

  • Comments 2

In a previous post (http://blogs.msdn.com/virtual_pc_guy/archive/2005/01/24/359650.aspx) - I discussed how Virtual PC / Virtual Server provide basic information about the host computer in the registry of the guest operating system.  Virtual Server extends this concept and allows users to specify custom parameters to be created in the guest operating system.  This is a very useful 'one way' communication channel - and is helpful in most situations where you want to run automated processes inside of the virtual machine.  Here is a very simple VBScript that takes three command line parameters - and uses them to create a custom entry in the registry of the guest operating system:

' || Script begins
'
' Connect to Virtual Server

Set virtualServer = CreateObject("VirtualServer.Application")

' Get virtual machine from the first command-line parameter
Set vm = virtualServer.FindVirtualMachine(WScript.Arguments(0))

' Set a registry parameter in the guest operating (where the key name is the
' second command-line parameter and the data stored in the key is the third
' command-line paramater

Result = vm.GuestOS.SetParameter(WScript.Arguments(1), WScript.Arguments(2))
'
' || Script ends

Once you have done this - you can check the value inside of the guest operating system with this script:

' || Script begins
'
' Setup constant

const HKEY_LOCAL_MACHINE = &H80000002

' Setup registry object (this is a single line)
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

' Set the key path and values to look at
strKeyPath = "SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters"
strValueName1 = WScript.Arguments(0)

' Get the values from the registry
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName1, dwValue1

' Display the results
WScript.Echo "The value for " & WScript.Arguments(0) & " is: " & dwValue1
'
' || Script ends

The only downside to this technique is that 'vm.GuestOS.SetParameter' can only be called when the virtual machine is actively running and Virtual Machine Additions is loaded.

Cheers,
Ben

Leave a Comment
  • Please add 6 and 5 and type the answer here:
  • Post
  • There is one non-obvious caveat that I have encountered with this trick.

    When the Guest OS has just booted up and user has just logged in, there is about a 30 second lag before the Parameter registry keys are populated in the Guest OS.

    So, even if you have a little daemon inside the Guest OS waiting on the Registry key to execute commands posted by automation from the Host machine, you need to wait a little while before deciding "Registry key not available -- install VM Additions Unattended" vs. "Registry key is not available yet; wait a while and retry again".

    //David
  • I'm trying to pass more then 1 argument to a windows xp mode application and it looks like a second parameter can not be added.

    This is the command line that works:

    vmsal.exe "SVGViewer" "||b5fa4934' "SVG Viewer" f:\pic1.svgz

    This command give me an "Incorrect file association." error:

    vmsal.exe "SVGViewer" "||b5fa4934' "SVG Viewer" f:\pic1.svgz "DETAIL1"

    Is it at all possible to pass additional command line arguments to an Windows XP Mode application?

    I can not find any official documentation on vmsal.exe, where can i find any?

Page 1 of 1 (2 items)