Win2008R2 Server Task Scheduler Problem

Discussions related to using VirtualBox on Windows hosts.

Win2008R2 Server Task Scheduler Problem

Postby kustodian » 10. Apr 2012, 16:49

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   Expand viewCollapse view
@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   Expand viewCollapse view
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   Expand viewCollapse view
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?
kustodian
 
Posts: 2
Joined: 10. Apr 2012, 16:30

Re: Win2008R2 Server Task Scheduler Problem

Postby mpack » 10. Apr 2012, 17:29

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.
mpack
Site Moderator
 
Posts: 27189
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Win2008R2 Server Task Scheduler Problem

Postby kustodian » 10. Apr 2012, 18:36

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.
kustodian
 
Posts: 2
Joined: 10. Apr 2012, 16:30

Re: Win2008R2 Server Task Scheduler Problem

Postby mpack » 10. Apr 2012, 18:57

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.
mpack
Site Moderator
 
Posts: 27189
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Win2008R2 Server Task Scheduler Problem

Postby Allanrbo » 30. Jun 2012, 13:53

I have the exact same problem. Did you find a solution?
Allanrbo
 
Posts: 2
Joined: 30. Jun 2012, 13:51

Re: Win2008R2 Server Task Scheduler Problem

Postby Allanrbo » 30. Jun 2012, 14:31

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.
Allanrbo
 
Posts: 2
Joined: 30. Jun 2012, 13:51

Re: Win2008R2 Server Task Scheduler Problem

Postby tburba » 23. Jan 2013, 19:38

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?
tburba
 
Posts: 5
Joined: 26. Jul 2011, 15:20
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Fedora, CentOS, Debian, Ubuntu, Windows XP, Windows 7

Re: Win2008R2 Server Task Scheduler Problem

Postby noteirak » 24. Jan 2013, 00:31

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...
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5182
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: Win2008R2 Server Task Scheduler Problem

Postby Airell » 3. Apr 2013, 13:43

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   Expand viewCollapse view
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.
Airell
 
Posts: 1
Joined: 3. Apr 2013, 13:27

Re: Win2008R2 Server Task Scheduler Problem

Postby mpack » 3. Apr 2013, 15:50

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.
mpack
Site Moderator
 
Posts: 27189
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP


Return to VirtualBox on Windows Hosts

Who is online

Users browsing this forum: No registered users and 19 guests