从Python通过COM控制VirtualBox?
我正在尝试通过 Python 的 COM 接口控制最新的 Sun VirtualBox。 但是,不幸的是,以下代码不起作用:
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 )
错误是一般“(-2147467262,'不支持此类接口',无,无)” 看来错误的部分是我通过 Python 处理的 COM。 任何人都可以看看并提出一些我做错的明显事情吗?
I'm trying to control latest Sun VirtualBox via it's COM interface from Python. But, unfortunately, the following code don't work:
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 )
Error is general "(-2147467262, 'No such interface supported', None, None)"
It seems that the wrong part is my COM handing via Python. Anyone can drop a look and suggest some obvious thing i'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是 FindMachine("kubuntu") 返回的对象不支持 IDispatch 接口,而 win32com 也不支持。
您可以使用我的
comtypes
包 http://starship.python。 net/crew/theller/comtypes/ 为此,但您需要修补存储库中的版本以使其与 VirtualBox 类型库一起使用。这是一个演示会话:
这是您需要的补丁:
The problem is that the object returned by
FindMachine("kubuntu")
does not support theIDispatch interface
, and win32com does not support that.You could use my
comtypes
package http://starship.python.net/crew/theller/comtypes/ for that, but you need to patch the version in the repository to make it work with the VirtualBox type libraries.Here's a demo session:
And here is the patch that you need: