For some time I've been running a nightly test process (Windows 7 64-bit host) on a VirtualBox guest (Windows XP 32-bit) which is restored to a known snapshot and started. The VM was controlled via a basic command script -
Code: Select all
VBoxManage snapshot "My Test VM" restore "Clean Machine"
VBoxManage startvm "My Test VM"
Code: Select all
C:\Program Files\Oracle\VirtualBox>VBoxManage snapshot "My Test VM" restore "Clean Machine"
Restoring snapshot d8903d92-a25f-4593-8380-3eafaa290d88
VBoxManage.exe: error: Cannot delete the current state of the running machine (machine state: Running)
VBoxManage.exe: error: Details: code VBOX_E_INVALID_VM_STATE (0x80bb0002), component Console, interface IConsole, callee IUnknown Context: "RestoreSnapshot(pSnapshot, pProgress.asOutParam())" at line 424 of file VBoxManageSnapshot.cpp
C:\Program Files\Oracle\VirtualBox>VBoxManage startvm "My Test VM"
VBoxManage.exe: error: The machine 'My Test VM' is already locked by a session (or being locked or unlocked)
VBoxManage.exe: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component Machine, interface IMachine, callee IUnknown Context: "LaunchVMProcess(a->session, sessionType.raw(), env.raw(), progress.asOutParam())" at line 561 of file VBoxManageMisc.cpp
Which brings me on to Part 2 of this problem. To resolve this new issue, I modified my batch file to pull the plug on the VM prior to reverting it:
Code: Select all
VBoxManage controlvm "My Test VM" poweroff
VBoxManage snapshot "My Test VM" restore "Clean Machine"
VBoxManage startvm "My Test VM"
Code: Select all
C:\Program Files\Oracle\VirtualBox>VBoxManage controlvm "My Test VM" poweroff
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
C:\Program Files\Oracle\VirtualBox>VBoxManage snapshot "My Test VM" restore "Clean Machine"
VBoxManage.exe: error: The session is not locked (session state: Unlocked)
VBoxManage.exe: error: Details: code E_UNEXPECTED (0x8000ffff), component Session, interface ISession, callee IUnknown Context: "COMGETTER(Console (console.asOutParam())" at line 284 of file VBoxManageSnapshot.cpp
C:\Program Files\Oracle\VirtualBox>VBoxManage startvm "My Test VM"
Waiting for VM "My Test VM" to power on...
VM "My Test VM" has been successfully started.
Code: Select all
C:\Program Files\Oracle\VirtualBox>VBoxManage controlvm "My Test VM" poweroff
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
C:\Program Files\Oracle\VirtualBox>VBoxManage snapshot "My Test VM" restore "Clean Machine"
Restoring snapshot d8903d92-a25f-4593-8380-3eafaa290d88
VBoxManage.exe: error: The object is not ready
VBoxManage.exe: error: Details: code E_ACCESSDENIED (0x80070005), component Console, interface IConsole, callee IUnknown Context: "RestoreSnapshot(pSnapshot, pProgress.asOutParam())" at line 424 of file VBoxManageSnapshot.cpp
C:\Program Files\Oracle\VirtualBox>VBoxManage startvm "My Test VM"
VBoxManage.exe: error: The machine 'My Test VM' is already locked by a session (or being locked or unlocked)
VBoxManage.exe: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component Machine, interface IMachine, callee IUnknown Context: "LaunchVMProcess(a->session, sessionType.raw(), env.raw(), progress.asOutParam())" at line 561 of file VBoxManageMisc.cpp