Python에서 COM을 통해 VirtualBox 제어?
-
05-07-2019 - |
문제
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, '그러한 인터페이스가 지원되지 않음', 없음, 없음)" "잘못된 부분은 파이썬을 통한 내 COM 인 것 같습니다. 누구나 외모를 떨어 뜨리고 내가 틀린 분명한 일을 제안 할 수 있습니까?
해결책
The problem is that the object returned by FindMachine("kubuntu")
does not support the IDispatch 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:
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
>>>
And here is the patch that you need:
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,
제휴하지 않습니다 StackOverflow