Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

What’s in pyvbox:

  • A complete implementation of the VirtualBox Main API

  • Create a VirtualBox instance and seamlessly explore the potential of VirtualBox’s amazing Main API

  • Pythonic functions and names.

  • Introspection, documentation strings, getters and setters, and more…

Project documentation at pythonhosted.org.

Project hosting provided by github.com.

[mjdorma+pyvbox@gmail.com]

Install

Simply run the following:

> python setup.py install

or PyPi:

> pip install pyvbox

Getting started

Exploring the library:

> ipython
In [1]: import virtualbox

In [2]: virtualbox?

In [3]: virtualbox.VirtualBox?

In [4]: virtualbox.library.IMachine?

In [5]: virtualbox.library.MachineState?

In [6]: virtualbox.library.MachineState.teleported?

Listing machines:

> ipython
In [1]: import virtualbox

In [2]: vbox = virtualbox.VirtualBox()

In [3]: print("VM(s):\n + %s" % "\n + ".join([vm.name for vm in vbox.machines]))
VM(s):
 + filestore
 + xpsp3
 + win7
 + win8
 + test_vm

Launch machine, take a screen shot, stop machine:

> ipython
In [1]: import virtualbox

In [2]: vbox = virtualbox.VirtualBox()

In [3]: session = virtualbox.Session()

In [4]: vm = vbox.find_machine('test_vm')

In [5]: progress = vm.launch_vm_process(session, 'gui', '')

In [6]: h, w, _, _, _, _ = session.console.display.get_screen_resolution(0)

In [7]: png = session.console.display.take_screen_shot_to_array(0, h, w, virtualbox.library.BitmapFormat.png)

In [8]: with open('screenshot.png', 'wb') as f:
  ....:     f.write(png)

In [9]: print(session.state)
Locked

In [10]: session.state
Out[10]: SessionState(2)

In [11]: session.state >= 2
Out[11]: True

In [12]: session.console.power_down()

Write text into a window on a running machine:

> ipython
In [1]: import virtualbox

In [2]: vbox = virtualbox.VirtualBox()

In [3]: vm = vbox.find_machine('test_vm')

In [4]: session = vm.create_session()

In [5]: session.console.keyboard.put_keys("Q: 'You want control?'\nA: 'Yes, but just a tad...'")

Execute a command in the guest:

> ipython
In [1]: import virtualbox

In [2]: vbox = virtualbox.VirtualBox()

In [3]: vm = vbox.find_machine('test_vm')

In [4]: session = vm.create_session()

In [5]: gs = session.console.guest.create_session('Michael Dorman', 'password')

In [6]: process, stdout, stderr = gs.execute('C:\\Windows\\System32\\cmd.exe', ['/C', 'tasklist'])

In [7]: print stdout

Image Name                   PID Session Name     Session#    Mem Usage
========================= ====== ================ ======== ============
System Idle Process            0 Console                 0         28 K
System                         4 Console                 0        236 K
smss.exe                     532 Console                 0        432 K
csrss.exe                    596 Console                 0      3,440 K
winlogon.exe                 620 Console                 0      2,380 K
services.exe                 664 Console                 0      3,780 K
lsass.exe                    676 Console                 0      6,276 K
VBoxService.exe              856 Console                 0      3,972 K
svchost.exe                  900 Console                 0      4,908 K
svchost.exe                 1016 Console                 0      4,264 K
svchost.exe                 1144 Console                 0     18,344 K
svchost.exe                 1268 Console                 0      2,992 K
svchost.exe                 1372 Console                 0      3,948 K
spoolsv.exe                 1468 Console                 0      4,712 K
svchost.exe                 2000 Console                 0      3,856 K
wuauclt.exe                  400 Console                 0      7,176 K
alg.exe                     1092 Console                 0      3,656 K
wscntfy.exe                 1532 Console                 0      2,396 K
explorer.exe                1728 Console                 0     14,796 K
wmiprvse.exe                1832 Console                 0      7,096 K
VBoxTray.exe                1940 Console                 0      3,196 K
ctfmon.exe                  1948 Console                 0      3,292 K
cmd.exe                     1284 Console                 0      2,576 K
tasklist.exe                 124 Console                 0      4,584 K

Using context to manage opened sessions and locks:

> ipython
In [1]: import virtualbox

In [2]: vbox = virtualbox.VirtualBox()

In [3]: vm = vbox.find_machine('test_vm')

In [4]: with vm.create_session() as session:
   ...:     with session.console.guest.create_session('Michael Dorman', 'password') as gs:
   ...:         print(gs.directory_exists("C:\\Windows"))
   ...:
True

On an already running VM, register to receive on guest keyboard events:

>ipython
In [1]: from virtualbox import library

In [2]: import virtualbox

In [3]: vbox = virtualbox.VirtualBox()

In [4]: vm = vbox.find_machine('test_vm')

In [5]: s = vm.create_session()

In [6]: def test(a):
   ...:     print(a.scancodes)
   ...:

In [7]: s.console.keyboard.set_on_guest_keyboard(test)
Out[7]: 140448201250560

In [8]: [35]
[23]
[163]
[151]
[57]
[185]
[35]
[24]
[163]
[152]

See gist for more pyvbox examples.

Issues

Source code for pyvbox is hosted on GitHub. Please file bug reports with GitHub’s issues system.

Compatibility

pyvbox utilises the VirtualBox project’s vboxapi to gain access to the underlying COM API primitives. Therefore, pyvbox is compatible on systems which have a running vboxapi.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyvbox-1.1.0.tar.gz (227.9 kB view details)

Uploaded Source

File details

Details for the file pyvbox-1.1.0.tar.gz.

File metadata

  • Download URL: pyvbox-1.1.0.tar.gz
  • Upload date:
  • Size: 227.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyvbox-1.1.0.tar.gz
Algorithm Hash digest
SHA256 199ee23122021d108d280bde2cb3589665fd02b0c715b0aacdccb7fe0b386e94
MD5 62cf3a4cdf1029306ee40a101a8d88ba
BLAKE2b-256 9255b47e4efccafe9c57323c08df0b70c643ad90ab41d13d4773e8524bd23463

See more details on using hashes here.

Release history Release notifications | RSS feed

2.1.1

2 files

2.1.0

2 files

1.3.2

1 file

1.3.1

1 file

1.2.0

1 file

This release

1.1.0 This release

1 file

1.0.0

1 file

0.2.2

1 file

0.2.1

0.2.0

1 file

0.1.6

1 file

0.1.5

1 file

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

0.1

1 file

0.0.7

1 file

0.0.6

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

1 file

0.0.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page