使用WMI在HyperV VM上应用最新快照时获取错误32775

时间:2014-02-07 00:53:44

标签: c# wmi hyper-v

当我尝试使用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.我还可以打印快照和虚拟机的名称,以便识别机器和快照时没有问题。

任何想法? 谢谢, 流星

1 个答案:

答案 0 :(得分:1)

发现问题,如果您想远程应用快照,显然需要关闭VM!也许在MSDN网站上太难提了。