- 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?