Re: Execute process inside VM
Posted: 28. Sep 2017, 13:48
The guest, that's where the login attempt is made
End user forums for VirtualBox
https://forums.virtualbox.org/
Code: Select all
C:\Program Files\Oracle\VirtualBox>vboxmanage.exe guestcontrol "W7 32-bit JAP" --username "Admin" --password "test" stat "c:\windows\explorer.exe"
VBoxManage.exe: error: The specified user was not able to logon on guest
VBoxManage.exe: error: Details: code VBOX_E_IPRT_ERROR (0x80bb0005), component GuestSessionWrap, interface IGuestSession, callee IUnknown
VBoxManage.exe: error: Context: "WaitForArray(ComSafeArrayAsInParam(aSessionWaitFlags), 30 * 1000, &enmWaitResult)" at line 938 of file VBoxManageGuestCtrl.cpp
Code: Select all
C:\Program Files\Oracle\VirtualBox>vboxmanage.exe guestcontrol "W7 32-bit JAP" --username "W7ProJapanesex86" --password "test" stat "c:\windows\explorer.exe"
Element "c:\windows\explorer.exe" found: Is a file
Code: Select all
# -*- coding: utf-8 -*-
import vboxapi
import glob
import time
mgr = vboxapi.VirtualBoxManager(None, None)
vbox = mgr.vbox
machine = vbox.findMachine("W7 32-bit JAP")
session = mgr.openMachineSession(machine) # locks at this point
# Launch VM
session = mgr.mgr.getSessionObject(vbox)
machine.lockMachine(session, mgr.constants.LockType_Shared)
console = session.console
try:
print "Session creation..."
guestSess = console.guest.createSession("W7ProJapanesex86", "test", None, None)
try:
print "Session created"
guestSess.waitFor(1, 30000)
if guestSess.status != mgr.constants.GuestSessionStatus_Started:
raise Exception, "Guest Session did not start after 30 sec"
time.sleep(5) # Let Windows stabilize
path = "C:/Windows/System32/arp.exe"
flag = [mgr.constants.ProcessCreateFlag_WaitForStdOut]
process = guestSess.processCreate(path, None, None, flag, 0)
print "Process created "
es = process.eventSource
el = es.createListener()
evtType = [mgr.constants.VBoxEventType_Any]
es.registerListener(el, evtType, False)
try:
print "Guest process created"
pwff1 = [mgr.constants.ProcessWaitForFlag_Start]
pwr = process.waitFor(pwff1[0], 30000)
keepLooking = True
while keepLooking:
ev = es.getEvent(el, 200)
if ev != None:
es.eventProcessed(el, ev)
stdOut = process.read(1, 64, 0)
print str(stdOut)
print str(process.status)
if "Terminated" in str(process.status):
break
print "Process exit code: " + process.exitCode
finally:
es.unregisterListener(el)
if "Terminated" not in str(process.status):
process.terminate()
finally:
print "Session close"
guestSess.close()
except Exception as e:
print(e)
if hasattr(e, 'message'):
print(e.message)
finally:
print "Machine unlock"
session.unlockMachine()