I am currently working on a projet using python3, and I encounter an issue with USB device attachement :
Host : Windows 10 (1903)
guest: Windows 7 sp1
Virtualbox API 5.2.XX
I read on the documentation that on Windows the device can be in BUSY state (and it is), after calling attachUSBDevice(), the device is then in HELD state.
As I read in the doc,
So I said to myself let's recall attachUSBDevice()Note: Due to differences in USB stack implementations in Linux and Win32, states USBDeviceState_
Busy and USBDeviceState_Unavailable are applicable only to the Linux
version of the product. This also means that (IConsole::attachUSBDevice()) can only
succeed on Win32 if the device state is USBDeviceState_Held.
the result of the second call is an exception:
Code: Select all
File "C:\Users\hch\AppData\Local\Temp\gen_py\3.6\D7569351-1750-46F0-936E-BD127D5BC264x0x1x3.py", line 1279, in AttachUSBDevice
, aCaptureFilename)
pywintypes.com_error: (-2147352567, 'Une exception s’est produite.', (0, None, None, None, 0, -2147467259), None)
vbox.VboxException: NS_ERROR_FAILURE: Une exception s’est produite.
raise VboxException(vboxErr(com_e))
Code: Select all
def attach_usb_device(mach, device):
session = None
try:
if mach.state == vb_const.MachineState_Running:
session = vb_ctx['global'].openMachineSession(mach)
console = session.console
if (device.state == vb_const.USBDeviceState_Available) or\
(device.state == vb_const.USBDeviceState_Busy):
console.attachUSBDevice(device.id, None)
if device.state == vb_const.USBDeviceState_Held:
console.attachUSBDevice(device.id, None)
except pythoncom.com_error as com_e:
raise VboxException(vboxErr(com_e))
else:
if session:
if session.state == vb_const.SessionState_Locked:
vb_ctx['global'].closeMachineSession(session)
thank for your help