在 Virtual Box 中还原虚拟机快照时出错
Error restore virtual machine snapshot in Virtual Box
我在项目中使用 VirtualBox 和 Virtual Box API Microsoft Com C++。
它是 VirtualBox 6.0.6 软件开发工具包 (SDK) 和 VirtualBox 6.0.6 平台包。
我有个问题。我想恢复早期创建的快照系统,但程序显示错误。
我的注释代码:
HRESULT rc;
IVirtualBoxClient *virtualBoxClient = nullptr;
IVirtualBox *virtualBox = nullptr;
IMachine *machine = nullptr;
ISession *session = nullptr;
IProgress *progress = nullptr;
ISnapshot* snapshot = nullptr;
BSTR sessiontype = SysAllocString(L"gui");
BSTR machineName = SysAllocString(L"Win7x64");
HRESULT rc = CoCreateInstance(CLSID_VirtualBoxClient, NULL, CLSCTX_INPROC_SERVER, IID_IVirtualBoxClient, (void**)&virtualBoxClient);
rc = virtualBoxClient->get_VirtualBox(&virtualBox);
// looking for a machine with a name Win7x64
rc = virtualBox->FindMachine(machineName, &machine);
// create a session object
rc = CoCreateInstance(CLSID_Session, NULL, CLSCTX_INPROC_SERVER, IID_ISession, (void**)&session);
if (!SUCCEEDED(rc))
{
printf("Error creating Session instance! rc = 0x%x\n", rc);
break;
}
// block the machine
machine->LockMachine(session, LockType::LockType_Shared);
// the name of the snapshot system
BSTR snapshotUUID = SysAllocString(L"Win7_test_snapshot");
// looking for a snapshot system
rc = machine->FindSnapshot(snapshotUUID, &snapshot);
// recover snapshot. ERROR: variable rc - E_NOTIMPL Not implemented.
rc = machine->RestoreSnapshot(snapshot, &progress);
printf("Starting VM, please wait ...\n");
//waiting for the end of the operation. Abnormal termination- progress == nullptr !
rc = progress->WaitForCompletion(-1);
// unlocking the machine
rc = session->UnlockMachine();
if (!SUCCEEDED(rc))
{
printf("Error restore state machine!\n");
break;
}
此外,我创建了一个简单的 C# 应用程序,并在那里得到了完全相同的错误。怎么了?这是错误 API ?我什至多次更改 OS(虚拟):
static void Main(string[] args)
{
VirtualBox.VirtualBox virtualBox = new VirtualBox.VirtualBox();
IMachine vmMachine = virtualBox.FindMachine("Win7x64VB");
Session session = new Session();
vmMachine.LockMachine(session, LockType.LockType_Shared);
IConsole console = session.Console;
// Restore snapshot
ISnapshot snapShot = vmMachine.FindSnapshot("Win7_snapshot1");
IProgress snapShotProgress = vmMachine.RestoreSnapshot(snapShot);
snapShotProgress.WaitForCompletion(300000);
// unlock before launch VMProcess
session.UnlockMachine();
IProgress launchVmProgess = vmMachine.LaunchVMProcess(session, "gui", "None");
launchVmProgess.WaitForCompletion(300000);
}
你能帮我吗,如何修复调用方法错误“RestoreSnapshot - E_NOTIMPL Not implemented”或者如何正确恢复系统快照?谢谢。
P.S.: 我在官方论坛上问过这个问题,没人帮我。
我找到了问题的解决方案。应使用会话的当前系统恢复快照。所以代码如下:
HRESULT rc = machine->LockMachine(session, LockType::LockType_Shared);
rc = machine->FindSnapshot(snapshotUUID, &snapshot);
IMachine* currentMachine(nullptr);
rc = session->get_Machine(¤tMachine);
rc = currentMachine->RestoreSnapshot(snapshot, &progress);
rc = progress->WaitForCompletion(300000);
rc = session->UnlockMachine();
它适用于此代码。
我在项目中使用 VirtualBox 和 Virtual Box API Microsoft Com C++。
它是 VirtualBox 6.0.6 软件开发工具包 (SDK) 和 VirtualBox 6.0.6 平台包。
我有个问题。我想恢复早期创建的快照系统,但程序显示错误。
我的注释代码:
HRESULT rc;
IVirtualBoxClient *virtualBoxClient = nullptr;
IVirtualBox *virtualBox = nullptr;
IMachine *machine = nullptr;
ISession *session = nullptr;
IProgress *progress = nullptr;
ISnapshot* snapshot = nullptr;
BSTR sessiontype = SysAllocString(L"gui");
BSTR machineName = SysAllocString(L"Win7x64");
HRESULT rc = CoCreateInstance(CLSID_VirtualBoxClient, NULL, CLSCTX_INPROC_SERVER, IID_IVirtualBoxClient, (void**)&virtualBoxClient);
rc = virtualBoxClient->get_VirtualBox(&virtualBox);
// looking for a machine with a name Win7x64
rc = virtualBox->FindMachine(machineName, &machine);
// create a session object
rc = CoCreateInstance(CLSID_Session, NULL, CLSCTX_INPROC_SERVER, IID_ISession, (void**)&session);
if (!SUCCEEDED(rc))
{
printf("Error creating Session instance! rc = 0x%x\n", rc);
break;
}
// block the machine
machine->LockMachine(session, LockType::LockType_Shared);
// the name of the snapshot system
BSTR snapshotUUID = SysAllocString(L"Win7_test_snapshot");
// looking for a snapshot system
rc = machine->FindSnapshot(snapshotUUID, &snapshot);
// recover snapshot. ERROR: variable rc - E_NOTIMPL Not implemented.
rc = machine->RestoreSnapshot(snapshot, &progress);
printf("Starting VM, please wait ...\n");
//waiting for the end of the operation. Abnormal termination- progress == nullptr !
rc = progress->WaitForCompletion(-1);
// unlocking the machine
rc = session->UnlockMachine();
if (!SUCCEEDED(rc))
{
printf("Error restore state machine!\n");
break;
}
此外,我创建了一个简单的 C# 应用程序,并在那里得到了完全相同的错误。怎么了?这是错误 API ?我什至多次更改 OS(虚拟):
static void Main(string[] args)
{
VirtualBox.VirtualBox virtualBox = new VirtualBox.VirtualBox();
IMachine vmMachine = virtualBox.FindMachine("Win7x64VB");
Session session = new Session();
vmMachine.LockMachine(session, LockType.LockType_Shared);
IConsole console = session.Console;
// Restore snapshot
ISnapshot snapShot = vmMachine.FindSnapshot("Win7_snapshot1");
IProgress snapShotProgress = vmMachine.RestoreSnapshot(snapShot);
snapShotProgress.WaitForCompletion(300000);
// unlock before launch VMProcess
session.UnlockMachine();
IProgress launchVmProgess = vmMachine.LaunchVMProcess(session, "gui", "None");
launchVmProgess.WaitForCompletion(300000);
}
你能帮我吗,如何修复调用方法错误“RestoreSnapshot - E_NOTIMPL Not implemented”或者如何正确恢复系统快照?谢谢。
P.S.: 我在官方论坛上问过这个问题,没人帮我。
我找到了问题的解决方案。应使用会话的当前系统恢复快照。所以代码如下:
HRESULT rc = machine->LockMachine(session, LockType::LockType_Shared);
rc = machine->FindSnapshot(snapshotUUID, &snapshot);
IMachine* currentMachine(nullptr);
rc = session->get_Machine(¤tMachine);
rc = currentMachine->RestoreSnapshot(snapshot, &progress);
rc = progress->WaitForCompletion(300000);
rc = session->UnlockMachine();
它适用于此代码。