问题是返回的对象FindMachine("kubuntu")
不支持IDispatch interface
,win32com不支持。
您可以为此使用我的comtypes
包http://starship.python.net/crew/theller/comtypes/,但您需要修补存储库中的版本以使其与 VirtualBox 类型库一起使用。
这是一个演示会话:
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
>>>
这是您需要的补丁:
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,