【发布时间】:2014-02-07 00:53:43
【问题描述】:
当我尝试使用 WMI 将我的虚拟机恢复到最新快照时,我不断收到错误 32775(此操作的状态无效)。我正在使用以下代码(顺便在 MSDN 网站上提供):
ManagementObject virtualSystemService = Utility.GetServiceObject(connectionScope,"Msvm_VirtualSystemManagementService");
ManagementBaseObject inParams =virtualSystemService.GetMethodParameters("ApplyVirtualSystemSnapshot");
ManagementObject vmSnapshot = GetLastVirtualSystemSnapshot(vm);
if (vmSnapshot != null)
{
inParams["SnapshotSettingData"] = vmSnapshot.Path.Path;
inParams["ComputerSystem"] = vm.Path.Path;
ManagementBaseObject outParams = virtualSystemService.InvokeMethod("ApplyVirtualSystemSnapshot", inParams, null);
if ((UInt32)outParams["ReturnValue"] == ReturnCode.Started)
{
if (Utility.JobCompleted(outParams, connectionScope))
{
Console.WriteLine("Snapshot was applied successfully.");
}
else
{
Console.WriteLine("Failed to apply snapshot.");
}
}
else if ((UInt32)outParams["ReturnValue"] == ReturnCode.Completed)
{
Console.WriteLine("Snapshot was applied successfully.");
}
else
{
Console.WriteLine("Apply virtual system snapshot failed with error {0}", outParams["ReturnValue"]);
}
}
else
{
Console.WriteLine("No Snapshots!");
}
我可以毫无问题地在 UI 上应用快照,并且我的虚拟机处于启用状态并且没有执行任何操作。操作系统是 Windows 2012。我还可以打印快照和虚拟机的名称,这样识别机器和快照就没有问题了。
有什么想法吗? 谢谢, 沙哈布
【问题讨论】: