Running VBoxManage.exe from Windows Task Scheduler

I have been trying to run VBoxManage.exe from the Windows Task Scheduler to periodically list vms. The problem I had was that it wouldn’t list the VM’s I had registered, even if the task was run as the user that created the VM’s and with the ‘Run with highest privileges’ selected.

When searching the Internet, I saw more people having difficulties running it this way, so I started experimenting. Using ‘psexec‘ and ‘runas’ (use the /savecred option and run it once manually from command line) did work when running the VBoxManage.exe as the VM’s creator user while being logged as someone else, but running it from the Task Scheduler still did not work.

When listing (or starting or stopping), it is looking for the VirtualBox.xml file in the .VirtualBox directory stored in the user’s profile directory. A tip from the VirtualBox forums was running “vboxmanage registervm” from the Task Scheduler before listing it… yes, that works! Now the VM was listed, but only that one was registered. Running it twice will give an error that it ‘has the same UUID as an existing virtual machine’, so it must have been stored somewhere in a VirtualBox.xml file. Searching the complete machine only gave me the one from my own profile with all the VM’s, not the one just registered… where is this VM stored and and which VirtualBox.xml?

It’s VBoxSVC.exe !!!

I used ‘procmon‘ to figure out what was called all the way. I filtered VBoxManage.exe from the Process Names, but no VirtualBox.xml called… so I cleared the filter… and there is was, VirtualBox.xml is called… from VBoxSVC.exe and started shortly as a service and disappears afterwards (use ‘procexp‘). It’s VBoxSVC.exe which is not run as a user, but always as the system account and it’s home directory is… ‘C:\Windows\System32\config\systemprofile‘. There is the .VirtualBox directory and VirtualBox.xml. Hidden from the Windows search!

VBoxSVC.exe in procmon

VBoxSVC.exe in procmon

Because VBoxSVC.exe called from the VBoxManage.exe process (I think, but it’s tree originates from wininit.exe / services.exe / svchost.exe), it’s seems not possible to start VBoxSVC.exe as an other user. I have tried to install the ‘psexec service’ or create a service with ‘sc’ and run it as service under the VM’s creator user, but it won’t stay alive (you can see it’s using the right user directory now) and I’m not even sure VBoxManage.exe will fall for it.

Make a junction

I got it running, I created a ‘junction‘ (a directory symlink for NTFS) to the .VirtualBox directory from C:\Windows\System32\config\systemprofile to my own user directory:

c:
cd c:\Windows\System32\config\systemprofile\
rename .VirtualBox _.VirtualBox
junction .VirtualBox C:\Users\Airell\.VirtualBox

Task scheduler ‘run as’ with highest privilege

When running the script with VBoxManage.exe from the Task Scheduler:

Run as with highest privilege

Run as with highest privilege

  • run it as the user who created the VM’s
  • select ‘Run task with highest privileges’ (without this option, the VBoxSVC.exe is not started)
  • –> make sure VirtualBox.exe is not running, this will lock the VirtualBox.xml !

Finally, my list of VM’s are now listed and can be stopped and started from the Windows Task Scheduler!

Sysinternals

I prefer working with Linux, but when running into trouble on Windows, I always use the tools from Sysinternals.

Happy VM Tasking!

Tagged . Bookmark the permalink.

6 Responses to Running VBoxManage.exe from Windows Task Scheduler

Leave a Reply

Your email address will not be published. Required fields are marked *