1 | #!python
|
---|
2 | #
|
---|
3 | #################################################################################
|
---|
4 | # This program is a simple interactive shell for VirtualBox. You can query #
|
---|
5 | # information and issue commands from a simple command line. #
|
---|
6 | # #
|
---|
7 | # It also provides you with examples on how to use VirtualBox's Python API. #
|
---|
8 | # This shell is even somewhat documented and supports TAB-completion and #
|
---|
9 | # history if you have Python readline installed. #
|
---|
10 | # #
|
---|
11 | # Enjoy. #
|
---|
12 | #################################################################################
|
---|
13 | #
|
---|
14 | #
|
---|
15 |
|
---|
16 | import sys, os
|
---|
17 | from win32com import universal
|
---|
18 | from win32com.client import gencache, DispatchWithEvents, Dispatch
|
---|
19 | from win32com.client import constants, getevents
|
---|
20 | import win32com.server.register
|
---|
21 | import win32com
|
---|
22 | import pythoncom
|
---|
23 | import win32api
|
---|
24 | import traceback
|
---|
25 |
|
---|
26 | from shellcommon import interpret
|
---|
27 |
|
---|
28 | class LocalManager:
|
---|
29 | def getSessionObject(self, vb):
|
---|
30 | return win32com.client.Dispatch("{3C02F46D-C9D2-4f11-A384-53F0CF917214}")
|
---|
31 |
|
---|
32 | vbox = None
|
---|
33 | mgr = LocalManager()
|
---|
34 | try:
|
---|
35 | vbox = win32com.client.Dispatch("{B1A7A4F2-47B9-4A1E-82B2-07CCD5323C3F}")
|
---|
36 | except Exception,e:
|
---|
37 | print "COM exception: ",e
|
---|
38 | traceback.print_exc()
|
---|
39 | sys.exit(1)
|
---|
40 |
|
---|
41 | # fake constants, while get resolved constants issues for real
|
---|
42 | # win32com.client.constants doesn't work for some reasons
|
---|
43 | class DummyInterfaces: pass
|
---|
44 | class SessionState:pass
|
---|
45 |
|
---|
46 | DummyInterfaces.SessionState=SessionState()
|
---|
47 | DummyInterfaces.SessionState.Open = 2
|
---|
48 |
|
---|
49 | ctx = {'mgr':mgr, 'vb':vbox, 'ifaces':DummyInterfaces(),
|
---|
50 | #'ifaces':win32com.client.constants,
|
---|
51 | 'remote':False, 'type':'mscom' }
|
---|
52 |
|
---|
53 | interpret(ctx)
|
---|
54 |
|
---|
55 | del vbox
|
---|