Pregunta

Estoy tratando de controlar la última Sun VirtualBox a través de su interfaz COM de Python. Pero, desafortunadamente, el siguiente código no funciona:

import win32com.client
VBOX_GUID = "{B1A7A4F2-47B9-4A1E-82B2-07CCD5323C3F}"
try :
  oVbox = win32com.client.Dispatch( VBOX_GUID )
  oVbox.FindMachine( "kubuntu" )
except Exception as oEx:
  print str( oEx )

El error es general " (- 2147467262, 'No hay tal interfaz compatible', Ninguno, Ninguno) " Parece que la parte incorrecta es mi entrega de COM a través de Python. Cualquiera puede echar un vistazo y sugerir alguna cosa obvia que estoy haciendo mal?

¿Fue útil?

Solución

El problema es que el objeto devuelto por FindMachine (" kubuntu ") no es compatible con la IDispatch interface , y win32com no lo admite.

Puede usar mi paquete comtypes http: // starship .python.net / crew / theller / comtypes / para eso, pero necesita parchear la versión en el repositorio para que funcione con las bibliotecas de tipo VirtualBox.

Aquí hay una sesión de demostración:

Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from comtypes.client import CreateObject
>>> box = CreateObject("VirtualBox.VirtualBox")
>>> m = box.FindMachine("Fedora")
>>> print m.State
4
>>> print m.CpuCount
1
>>> print m.Name
Fedora
>>>

Y aquí está el parche que necesita:

Index: automation.py
===================================================================
--- automation.py   (revision 507)
+++ automation.py   (working copy)
@@ -753,6 +753,8 @@
     c_float: VT_R4,
     c_double: VT_R8,

+    c_ulonglong: VT_I8,
+
     VARIANT_BOOL: VT_BOOL,

     BSTR: VT_BSTR,
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top