当我在编辑器中运行此代码时,它可以完美运行:(不是一个错误)
$vm = 0
$vpc=new-object –com VirtualPC.Application –Strict
foreach ($vm in $vpc.VirtualMachines){}
$broken = Get-WmiObject Win32_PnPEntity | where {$_.ConfigManagerErrorCode -ne 0}
$usbDevice = $vpc.USBDeviceCollection | ? {$_.DeviceString -eq $usb} | select -first 1
$vm.AttachUSBDevice($usbDevice)
当我将此代码放在一行中时;在最后:
$vm = 0; $vpc=new-object –com VirtualPC.Application –Strict; foreach ($vm in $vpc.VirtualMachines){}; $broken = Get-WmiObject Win32_PnPEntity | where {$_.ConfigManagerErrorCode -ne 0}; $usbDevice = $vpc.USBDeviceCollection | ? {$_.DeviceString -eq $usb} | select -first 1; $vm.AttachUSBDevice($usbDevice)
它给了我 0×80020005 错误:
Exception calling "AttachUSBDevice" with "1" argument(s): "Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_T
YPEMISMATCH))"
At line:1 char:293
+ $vpc=new-object -com VirtualPC.Application -Strict; $vm = $vpc.findVirtualMachine("Windows XP Mode"); $broken = Get-W
miObject Win32_PnPEntity | where {$_.ConfigManagerErrorCode -ne 0}; $usbDevice = $vpc.USBDeviceCollection | ? {$_.Devic
eString -eq $usb} | select -first 1; $vm.AttachUSBDevice <<<< ($usbDevice)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
有人知道如何解决这个问题吗?
(我知道代码有点奇怪,但这不是重点:))