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



当我尝试使用WMI将VM还原为最新快照时,我会不断获得错误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上应用快照,并且我的VM处于启用状态,并且没有做任何事情。OS是Windows2012。我还可以打印快照和VM的名称,因此识别机器和快照没有问题。

有什么想法吗?谢谢,Shahab

发现了问题,显然,如果要远程应用快照,则需要关闭VM!也许在MSDN网站上很难提及这一点。