Page 1 of 1

Win2008R2 Server Task Scheduler Problem

Posted: 10. Apr 2012, 16:49
by kustodian
I have a Windows Server 2008 R2 which is running VirtualBox 4.1.12. I created a script which powers off a virtual machine, restores a snapshot and than it powers on that virtual machine. The script looks like this:

Code: Select all

@echo off

set VMNAME=WinXP
set VMNAMESNAP=WinXP_Restore

set PATH=%PATH%;"c:\Program Files\Oracle\VirtualBox"

echo Powerering VM off...
VBoxManage controlvm %VMNAME% poweroff
timeout /t 10 /nobreak

echo Restoring snapshot...
VBoxManage snapshot %VMNAME% restore %VMNAMESNAP%

echo Turning VM on...
VBoxManage startvm %VMNAME%

timeout /t 5
When I run this script as an administrar (who created this VM) everything works fine, but if I create a scheduled task which I set to be run as the administrator I get this error message (I redirected stdout and stderr in the task to a log file):

Code: Select all

VBoxManage.exe: error: Could not find a registered machine named 'WinXP'
VBoxManage.exe: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBox, interface IVirtualBox, callee IUnknown
Context: "FindMachine(Bstr(a->argv[0]).raw(), machine.asOutParam())" at line 97 of file VBoxManageControlVM.cpp
I tried giving a full path to the virtual machine (the WinXP.vbox file), but then I get a similar result:

Code: Select all

VBoxManage.exe: error: Could not find a registered machine named 'd:\Virtual Box VMs\WinXP\WinXP.vbox'
VBoxManage.exe: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBox, interface IVirtualBox, callee IUnknown
Context: "FindMachine(Bstr(a->argv[0]).raw(), machine.asOutParam())" at line 97 of file VBoxManageControlVM.cpp
For some reason the VBoxManage cannot get the list of available VMs from "c:\Users\Administrator\.VirtualBox", even though everything works if I manually run it. I tried setting VBOX_USER_HOME to this directory on top of the bat file, but this didn't help.

Does anyone have an idea how to solve this problem?

Re: Win2008R2 Server Task Scheduler Problem

Posted: 10. Apr 2012, 17:29
by mpack
There is a difference between the account of a user called "Admin" and the account of a user which happens to have admin privileges. VirtualBox stores a separate VirtualBox.xml for each named user, in that user's <userdoc>\.VirtualBox folder. For a VM to be accessible by more than one user account, you create the VM using one account, and use Machine|Add... to add the VM in the other account.

Re: Win2008R2 Server Task Scheduler Problem

Posted: 10. Apr 2012, 18:36
by kustodian
mpack wrote:There is a difference between the account of a user called "Admin" and the account of a user which happens to have admin privileges. VirtualBox stores a separate VirtualBox.xml for each named user, in that user's <userdoc>\.VirtualBox folder. For a VM to be accessible by more than one user account, you create the VM using one account, and use Machine|Add... to add the VM in the other account.
I understand that, that's why I created the VM with the account 'administrator' and set that VM to be run by that exact account in the Scheduled Task, so this shouldn't be an issue.

I even put a 'set' command at the start of the batch file and it is telling me the "%USERPROFILE%" variable is "C:\Users\Administrator", which is correct and that folder contains the ".VirtualBox" folder, which has all the information about that administrator's virtual boxes.

Re: Win2008R2 Server Task Scheduler Problem

Posted: 10. Apr 2012, 18:57
by mpack
Well, in that case I have no idea what your problem might be. It clearly isn't finding the VirtualBox.xml file, but you seem to have ruled out all possible reasons for that to happen.

Re: Win2008R2 Server Task Scheduler Problem

Posted: 30. Jun 2012, 13:53
by Allanrbo
I have the exact same problem. Did you find a solution?

Re: Win2008R2 Server Task Scheduler Problem

Posted: 30. Jun 2012, 14:31
by Allanrbo
Found a workaround now: ran "vboxmanage registervm" on the .vbox file in the script started from the scheduled task. Apparently there is some difference in the enviroment started from scheduled tasks, even though virtualbox and vboxheadless has no problem with being started interactively from the exact same user, both in an elevated prompt and a non-elevated prompt.

Re: Win2008R2 Server Task Scheduler Problem

Posted: 23. Jan 2013, 19:38
by tburba
Allanrbo wrote:"vboxmanage registervm" on the .vbox file in the script started from the scheduled task
I'm stuck with Win8 and the same problem in 4.2.6.

At first attempts, if run from a scheduled task, "vboxmanage registervm" simply sat there with 0% CPU and slowly dropping Memory (Private working set), while the script waited forever for it to finish. I tried to run as Administrator, tried to tick the box "at highest privileges", no change.

I rebooted the entire host a couple of times. Eventually the situation changed a bit: now "vboxmanage registervm" works the same as if the script was run manually (not from a scheduled task) -- it refuses with a message about the VM being already registered. But, "vboxmanage startvm" still hangs in case of --type gui. No logs are created neither for this particular VM nor in the .\VirtualBox folder (I cleaned both in advance). There are no new events in the Event Log.

I've heard numerous stories of programming horror about Session 0 isolation, so let's assume that --type gui is incompatible with Scheduled Tasks by design. But --type headless is also problematic. In that case the VM starts and I can use its services via network interfaces, however the VirtualBox Manager sees it as Powered off -- which means it can't be shut down from there. Apparently "vboxmanage controlvm ... acpipowerbutton" also doesn't see it as running, so I won't be able to automate the shutdown. If the script with --type headless is run manually instead of scheduled tasks, then all is well: Preview is updating, state is depicted adequately.

A few months have passed since the last post. Are there any updates on the matter?

Re: Win2008R2 Server Task Scheduler Problem

Posted: 24. Jan 2013, 00:31
by noteirak
Overall, and as a frustrated admin, simply don't use the task scheduler.
Regardless of which user you set it to run to, the issue will be that it is actually not _quite_ running as that user, there is a mix mode on how things will run.

So my best advice is : don't use it - it will break your applications...

Re: Win2008R2 Server Task Scheduler Problem

Posted: 3. Apr 2013, 13:43
by Airell
kustodian wrote:I have a Windows Server 2008 R2 which is running VirtualBox 4.1.12. I created a script which powers off a virtual machine, restores a snapshot and than it powers on that virtual machine. The script looks like this:
For some reason the VBoxManage cannot get the list of available VMs from "c:\Users\Administrator\.VirtualBox", even though everything works if I manually run it. I tried setting VBOX_USER_HOME to this directory on top of the bat file, but this didn't help.

Does anyone have an idea how to solve this problem?
The problem is that it's not VBoxManage.exe who is searching for the VirtualBox.xml in .VirtualBox, it's VBoxSVC.exe. Started from the Windows task scheduler this process is started still under the system account, even if VBoxManage.exe was 'run as' as the VM's creator.

VBoxSVC.exe running as system is looking in C:\Windows\System32\config\systemprofile for the \.VirtualBox\VirtualBox.xml and this file can not be found with simple searching.

I made a junction from C:\Windows\System32\config\systemprofile to the VM's creator directory:

Code: Select all

cd c:\Windows\System32\config\systemprofile\
rename .VirtualBox _.VirtualBox
junction .VirtualBox C:\Users\MeOrYou\.VirtualBox
Trying to 'run as' VBoxSVC.exe as an other user did not work for me, I sticked with the junction (get it from sysinternals, it's my first post, unable to post link's)

Cheers, Airell.

Re: Win2008R2 Server Task Scheduler Problem

Posted: 3. Apr 2013, 15:50
by mpack
Thanks for the mention of Junction, a free (SysInternals) tool that I hadn't heard about before. The issue of dealing with Windows drive letters changing has cropped up several times, this looks potentially useful as a solution.