Posts for October 2010

Floppy support in Windows Virtual PC 7

Windows Virtual PC 7 is the successor to Virtual PC 2007, and the only version of Virtual PC that can run on Windows 7. It's freely available to anyone, and if you have Windows 7 Professional or Ultimate, you can also download Windows XP Mode, a virtual machine of Windows XP that allows you to run applications that may not otherwise work on Windows 7.

It seems however that Microsoft has removed the UI for using floppy disks with Windows Virtual PC 7. It was there in Virtual PC 2007, and now it's not. However, here's the thing: they only removed the UI, not the functionality itself.

The functionality for using floppy disks is still available in Windows Virtual PC 7, but it's only accessible via the COM object, which is not very convenient. Fortunately, Windows 7 also includes PowerShell, a very powerful shell scripting environment, that allows us to make things a bit easier.

Below, I present three PowerShell scripts: one to create virtual floppy disk images, one to attach floppy disks to a VM, and one to release them. The latter two can be used with both virtual floppy disk images, or a real floppy drive on the host computer.

You can download all three scripts here. Or you can just copy/paste them into a file, whichever you prefer. Note that you'll need to configure PowerShell to allow unsigned scripts to run, or sign the scripts.

Anyway, here are the scripts:

Create-VirtualFloppy.ps1:

param(
    [parameter(Position=0, Mandatory=$true)][string]$Path
)

$vpc = New-Object -ComObject "VirtualPC.Application"
if( -not [System.IO.Path]::IsPathRooted($Path) )
{
    # CreateFloppyDiskImage requires an absolute path
    [Environment]::CurrentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath
    $Path = [System.IO.Path]::GetFullPath($Path)
}
$vpc.CreateFloppyDiskImage($Path, 2)

Attach-VirtualFloppy.ps1:

param(
  [parameter(Position=0, Mandatory=$true)][string]$VirtualMachineName,
  [parameter(Position=1, Mandatory=$true)][string]$FloppyPath,
  [parameter(Mandatory=$false)][Switch]$HostDrive
)

$vpc = New-Object -ComObject "VirtualPC.Application"
$vm = $vpc.FindVirtualMachine($VirtualMachineName)

if( $vm -eq $null )
{
    Write-Error "Virtual machine $vm not found."
}
else
{
    if( $HostDrive )
    {
        $vm.FloppyDrives.Item(1).AttachHostDrive($FloppyPath)
    }
    else
    {
        if( -not [System.IO.Path]::IsPathRooted($FloppyPath) )
        {
            # AttachImage requires an absolute path
            [Environment]::CurrentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath
            $FloppyPath = [System.IO.Path]::GetFullPath($FloppyPath)
        }
        $vm.FloppyDrives.Item(1).AttachImage($FloppyPath)
    }
}

Release-VirtualFloppy.ps1:

param(
  [parameter(Position=0, Mandatory=$true)][string]$VirtualMachineName
)

$vpc = New-Object -ComObject "VirtualPC.Application"
$vm = $vpc.FindVirtualMachine($VirtualMachineName)

if( $vm -eq $null )
{
    Write-Error "Virtual machine not found."
}
else
{
    if( $vm.FloppyDrives.Item(1).ImageFile -ne $null )
    {
        $vm.FloppyDrives.Item(1).ReleaseImage()
    }
    elseif( $vm.FloppyDrives.Item(1).HostDriveLetter -ne $null )
    {
        $vm.FloppyDrives.Item(1).ReleaseHostDrive()
    }
    else
    {
        Write-Warning "No virtual floppy is attached to the virtual machine $VirtualMachineName."
    }
}

Using the scripts is pretty simple. Run PowerShell, navigate to the directory where you put the scripts, and invoke them. Remember that you need to enable execution of unsigned scripts (Set-ExecutionPolicy RemoteSigned), or sign the scripts.

The following example creates a virtual floppy drive image called sample.vfd, attaches it to the Windows XP Mode virtual machine, and then releases it again:

.\Create-VirtualFloppy.ps1 sample.vfd
.\Attach-VirtualFloppy.ps1 "Windows XP Mode" sample.vfd
.\Release-VirtualFloppy.ps1 "Windows XP Mode"

Please note that the virtual machine must be running for attach and release to work.

The following example attaches the host floppy drive A and then releases it again:

.\Attach-VirtualFloppy.ps1 "Windows XP Mode" A -HostDrive
.\Release-VirtualFloppy.ps1 "Windows XP Mode"

And that's it! Now you can use floppy disks with Windows Virtual PC 7 once again.

Categories: General computing
Posted on: 2010-10-17 06:20 UTC. Show comments (23)

Singapore

Last month, on September 13th to 17th, I attended the 36th International Conference on Very Large Databases (VLDB 2010) in Singapore, to present a paper at the Ph.D. workshop.

Not only was this the first time I've been to such a large international conference (which was very interesting because it allowed me to talk to a lot of experts in my field and see what other people are doing), it was also the first time I ever visited Singapore.

Fortunately, I was able to get some time for sightseeing, and these pictures are the result. :)

Show images (129)

Categories: University, Personal
Posted on: 2010-10-16 08:55 UTC. Show comments (5)

Latest posts

Categories

Archive

Syndication

RSS Subscribe

;