Page 2 of 2

Re: Execute process inside VM

PostPosted: 28. Sep 2017, 13:48
by noteirak
The guest, that's where the login attempt is made

Re: Execute process inside VM

PostPosted: 28. Sep 2017, 14:50
by Bypus
I can't find anything on the time i launched the script.
Do you think it could be because the host is in a private network (domain) and the guest is not ?

Re: Execute process inside VM

PostPosted: 28. Sep 2017, 14:52
by noteirak
I can't speculate at this point. Are you able to login on the guest with the same credentials in a regular desktop session?

Re: Execute process inside VM

PostPosted: 28. Sep 2017, 15:03
by Bypus
I'll try it on a personnal computer then.
What do you mean ? I have only one Administrator session on the VM (GUI talking) named "Admin" and password "test" that i can open. With the createSession() function (script talking) i use the same credentials (user = "Admin", password = "test")

Re: Execute process inside VM

PostPosted: 28. Sep 2017, 15:10
by noteirak
is "Admin" the name of the user or the actual username that you use when loging in Windows? If yes, then you'll need to figure out why the security policy in Windows doesn't let you login.

A good starting point would be to ensure you can run the command using vboxmanage - See User Manual section.
It covers a lot of details on the requirements, pitfalls and so. If it works with vboxmanage, then the issue is still in the code. If it doesn't work with vboxmanage, your guest OS is not configured properly.

Re: Execute process inside VM

PostPosted: 28. Sep 2017, 15:52
by Bypus
Ok so, i might have messed up with the GUI:
Code: Select all   Expand viewCollapse view
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

Username "Admin" that was actually changed through GUI returns an error
Code: Select all   Expand viewCollapse view
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

Original username "W7ProJapanesex86" returns something.
In the script, it still returns the error with the original username
Here is the code just in case:
Code: Select all   Expand viewCollapse view
# -*- 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()

Re: Execute process inside VM

PostPosted: 28. Sep 2017, 16:02
by noteirak
Well just put the right path of the command you want to run, that seems to be the error here, exactly like the error you get with vboxmanage.
Nothing wrong with the code itself it seems!

Re: Execute process inside VM

PostPosted: 28. Sep 2017, 16:18
by Bypus
Nope, doesn't work.
It seems like it ignores the guestSess.waitFor(1, 30000) since it doesn't wait for 30 seconds, and if i remove waitFor(), Exception "Guest Session did not start after 30 sec" is raised (2 times ?)

Re: Execute process inside VM

PostPosted: 28. Sep 2017, 16:19
by noteirak
Then I'm out of ideas I'm afraid, it could be an issue with the python SDK itself... Hopefully someone with more experience on it might have a clue

Re: Execute process inside VM

PostPosted: 28. Sep 2017, 16:23
by Bypus
Ok then, thanks a lot for your help anyway !