当前位置: 主页 > 服务器技术 > Mail服务器 > 在Windows Virtual PC中使用软盘

在Windows Virtual PC中使用软盘

时间:2009-10-30来源:互联网 点击:
许多Windows Virtual PC用户并不需要在他们的虚拟机中使用软盘,当然软盘的常规应用已经成为了历史。但是,仍然会有些用户需要使用软盘——许多人认为无法在VPC中实现,因为没有一个用户界面可以让用户这么做。

当然,这并不是最终答案,您当然可以在VPC中使用软盘,不过在这么做之前您需要以下脚本来帮助你。


VBscript:
Option Explicit

‘ Define constants for floppy drive attachment types
CONST vmFloppyDrive_None = 0
CONST vmFloppyDrive_Image = 1
CONST vmFloppyDrive_HostDrive = 2

Dim namedArguments, argumentError, vpc, vm, vmName, action, floppy, vmFloppyDrive

‘ Check that the script is running at the command line.
If UCase(Right(Wscript.FullName, 11)) = “Wscript.EXE” Then
Wscript.Echo “This script must be run under Cscript.”
Wscript.Quit
End If

‘ Get the virtual machine name / floppy commands from the command-line arguments
Set namedArguments = Wscript.Arguments.Named

argumentError = false

If namedArguments.Exists(”vm”) Then
vmName = namedArguments.Item(”vm”)
Else
argumentError = true
End If

If namedArguments.Exists(”action”) Then
action = namedArguments.Item(”action”)
Else
argumentError = true
End If

If namedArguments.Exists(”floppy”) Then
floppy = namedArguments.Item(”floppy”)
Else
If (not ((action = “info”) or (action = “disconnect”))) Then
argumentError = true
End If
End If

‘ Display usage information if wrong arguments are provided
if argumentError then
Wscript.Echo “Missing command-line argument”
Wscript.Echo
Wscript.Echo “Usage: FloppyDrive.vbs /vm:” & chr(34) & “Name of virtual machine to be started” & chr(34)
Wscript.Echo
Wscript.Echo “ /action:info – to display information about the current floppy configuration”
Wscript.Echo “ disconnect – to disconnect any attached floppy disk or floppy disk image”
Wscript.Echo “ vfd – to attach a virtual floppy disk image”
Wscript.Echo “ physical – to attach a physical floppy disk”
Wscript.Echo
Wscript.Echo “ /floppy:name – where name is either the full name and path for a virtual”
Wscript.Echo “ floppy disk or the letter of a physical disk to attach”
Wscript.Echo
Wscript.Quit
end if

‘ Attempt to connect to Virtual PC
On Error Resume Next
Set vpc = CreateObject(”VirtualPC.Application”)
If Err.Number <> 0 Then
Wscript.Echo “Unable to connect to Virtual PC.”
Wscript.Quit
End if
On Error Goto 0

‘ Get virtual machine object
Set vm = vpc.FindVirtualMachine(vmName)

‘ Get the floppy drive
set vmFloppyDrive = vm.FloppyDrives.item(1)

‘ Perform the specified action
Select Case action

‘ Display floppy disk information
case “info”
wscript.echo “Floppy disk information”
wscript.echo “=======================”

‘ Different information is needed for each attachment type
select case vmFloppyDrive.Attachment
case vmFloppyDrive_None
wscript.echo “Floppy Attachment : No floppy disk attached”
wscript.echo “Drive Number : ” & vmFloppyDrive.DriveNumber
case vmFloppyDrive_Image
wscript.echo “Floppy Attachment : Floppy disk image attached”
wscript.echo “Drive Number : ” & vmFloppyDrive.DriveNumber
wscript.echo “Image File : ” & vmFloppyDrive.ImageFile
case vmFloppyDrive_HostDrive
wscript.echo “Floppy Attachment : Physical floppy disk attached”
wscript.echo “Drive Number : ” & vmFloppyDrive.DriveNumber
wscript.echo “Host Drive Letter : ” & vmFloppyDrive.HostDriveLetter
end select

‘ Disconnect the current floppy disk
case “disconnect”

wscript.echo “Disconnecting the floppy disk.”

‘ A different method is used to disconnect a floppy disk image than for a physical disk
select case vmFloppyDrive.Attachment
case vmFloppyDrive_Image
vmFloppyDrive.ReleaseImage
case vmFloppyDrive_HostDrive
vmFloppyDrive.ReleaseHostDrive
end select

‘ Attach a floppy disk image
case “vfd”

wscript.echo “Attaching ” & floppy & ” to the floppy drive.”
vmFloppyDrive.AttachImage(floppy)

‘ Attach a physical floppy disk
case “physical”

wscript.echo “Attaching physical disk ” & floppy & “: to the floppy drive.”
vmFloppyDrive.AttachHostDrive(floppy)

‘ Catch invalid actions
case else
wscript.echo “Invalid action provided. Info, disconnect, vfd and physical are valid options.”

end select

wscript.echo

PowerShell:
param([string]$vmName, [string]$action, [string]$floppy)

$argumentError = 0

# Check for correct command-line arguments
If ($vmName -eq “”)
{$argumentError = 1}

If ($action -eq “”)
{$argumentError = 1}

If ($floppy -eq “”)
{
if ((!([string]::Compare($action, “vfd”, $True))) -or (!([string]::Compare($action, “physical”, $True))))
{$argumentError = 1}
}

# Display usage information if wrong arguments are provided
If ($argumentError -eq 1)
{
write-host “Missing command-line argument.”
write-host “USage: FloppyDrive.ps1 -vmName `”Name of virtual machine`”"
write-host “ -action info – to display information about the current floppy configuration”
write-host “ disconnect – to disconnect any attached floppy disk or floppy disk image”
write-host “ vfd – to attach a virtual floppy disk image”
write-host “ physical – to attach a physical floppy disk”
write-host
write-host “ -floppy name – where name is either the full name and path for a virtual”
write-host “ floppy disk or the letter of a physical disk to attach”
exit
}

# Connect to Virtual PC
$vpc=new-object –com VirtualPC.Application –Strict

# Get virtual machine object
$vm = $vpc.FindVirtualMachine($vmName)

# Get the floppy drive
$vmFloppyDrive = $vm.FloppyDrives.item(1)

# Perform the specified action
switch ($action)
{

# Display floppy disk information
“info” {
write-host “Floppy disk information”
write-host “=======================”

# Different information is needed for each attachment type
switch ($vmFloppyDrive.Attachment)
{
0 {
write-host “Floppy Attachment : No floppy disk attached”
write-host “Drive Number : ” $vmFloppyDrive.DriveNumber}
1 {
write-host “Floppy Attachment : Floppy disk image attached”
write-host “Drive Number : ” $vmFloppyDrive.DriveNumber
write-host “Image File : ” $vmFloppyDrive.ImageFile }
2 {
write-host “Floppy Attachment : Physical floppy disk attached”
write-host “Drive Number : ” $vmFloppyDrive.DriveNumber
write-host “Host Drive Letter : ” $vmFloppyDrive.HostDriveLetter }
}
}

# Disconnect the current floppy disk
“disconnect” {

write-host “Disconnecting the floppy disk.”

# A different method is used to disconnect a floppy disk image than for a physical disk
switch ($vmFloppyDrive.Attachment)
{
1 {$vmFloppyDrive.ReleaseImage()}
2 {$vmFloppyDrive.ReleaseHostDrive()}
}
}

# Attach a floppy disk image
“vfd” {
write-host “Attaching ” $floppy ” to the floppy drive.”
$vmFloppyDrive.AttachImage($floppy)
}

# Attach a physical floppy disk
“physical” {
write-host “Attaching physical disk ” $floppy “: to the floppy drive.”
$vmFloppyDrive.AttachHostDrive($floppy)
}
# Catch invalid actions
default {write-host “Invalid action provided. Info, disconnect, vfd and physical are valid options.”}
}

这些脚本并非VPC原生支持的,运行后可能会报错,但是没关系。之后你就可以用虚拟机连接物理或虚拟的软盘了。当然使用前请检查软盘驱动运行正常哦!
站长资讯网
. TAG: VIRTUAL WINDOWS 软盘 vps

查看[在Windows Virtual PC中使用软盘]所有评论
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:
推荐内容最近更新人气排行
关于我们 | 友情链接 | 网址推荐 | 常用资讯 | 网站地图 | RSS | 网站留言