Developing VM-Typer (new series)

Developing VM-Typer (new series)

Rate This
  • Comments 4

The other weekend I was playing around with Virtual Server - and installing Windows Server 2003 in a virtual machine.  When I got to the stage where I needed to enter a product key - I thought: "How annoying - I wish there was an easy way to just copy and paste stuff like this into the virtual machine".  Three hours later I had finished putting together a program that allowed me to do just that - called "VM-Typer" (now I just have to perform about 500 more installations to get those three hours back :-).  Over the next couple of weeks I will outline what was involved.

The first task was to put together some basic UI:

VMTyper UI  

And then to make sure that the application:

  1. Uses the MTA model (as discussed here: )
  2. Calls CoInitializeSecurity before launching the main application (as discussed here: )

As this is a relatively simple program which does not need any STA components - I decided to just set the entire application to use the MTA model:

Imports System.Reflection
Imports Microsoft.VirtualServer.Interop

Public Class Form1

Inherits System.Windows.Forms.Form

'Virtual Server Connection
Private virtualServer As VMVirtualServer = Nothing

'Constants for CoInitializeSecurity
Private Const EOAC_DYNAMIC_CLOAKING As Long = 64

#Region "CoInitializeSecurity"
' Create a SUB with PreserveSig:=FALSE so the COM InterOp layer will
' perform the error checking and throw an exception, instead of using
' a Function and returning an HRESULT.
<DllImport("ole32.dll", _
, _
, _
      EntryPoint:="CoInitializeSecurity", _
      CallingConvention:=CallingConvention.StdCall, _
False)> _
Private Shared Sub CoInitializeSecurity( _
      ByVal pSD As IntPtr, _
      ByVal cAuthSvc As
Int32, _
      ByVal asAuthSvc As IntPtr, _
      ByVal pReserved1 As IntPtr, _
      ByVal dwAuthnlevel As UInt32, _
      ByVal dwImpLevel As UInt32, _
      ByVal pAuthInfo As IntPtr, _
      ByVal dwCapabilities As UInt32, _
      ByVal pvReserved2 As IntPtr)
End Sub

#End Region

#Region " Windows Form Designer generated code "
#End Region

'Enable MTA thread apartment model
<MTAThread()> _
   Shared Sub main()

   'Enable XP Style skins

CoInitializeSecurity(System.IntPtr.Zero, -1, System.IntPtr.Zero, System.IntPtr.Zero, _
            Convert.ToUInt32(RPC_C_AUTHN_LEVEL_PKT_PRIVACY), _
            Convert.ToUInt32(RPC_C_IMP_LEVEL_IMPERSONATE), System.IntPtr.Zero, _
            Convert.ToUInt32(EOAC_DYNAMIC_CLOAKING), System.IntPtr.Zero)

   'Start the application once CoInitializeSecurity has been called
   Application.Run(New Form1)

   End Sub

Next week we will take this base and start working on connecting to Virtual Server and getting the information we need.


Leave a Comment
  • Please add 8 and 4 and type the answer here:
  • Post
  • I'm not trying to be the devil's advocate, but Virtual PC *should* have a copy&paste option. I know VMWare (need more than Windows alone) does, and it's a feature I use a lot. When testing your software(-installations) under different OS-es, copy&paste of license-keys saves you a lot of typing and annoyance.

    Very nice solution, though. The start of a Virtual-PC-macro-editor? Keep up the good work.

  • Hi Reginald,

    Virtual PC does support copy and paste - Virtual Server does not.

  • I did not think I would need this until I realized that I have most of the XP and 2003 keys memorized!
  • is there possible to send keys stroke from host to vm player (win xp on it) ???

Page 1 of 1 (4 items)