从C#重命名Hyper-V WMI V2中的快照 [英] Rename a snapshot in Hyper-V WMI V2 from C#
本文介绍了从C#重命名Hyper-V WMI V2中的快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用root \ virtualization \ v2重命名Hyper-V快照(检查点).到目前为止,没有像Msvm_VirtualSystemSnapshotService的ModifySystemSettings或ModifyVirtualSystem或Msvm_VirtualSystemManagementService这样的标准方法有用.
I am trying to rename a Hyper-V snapshot (checkpoint) using root\virtualization\v2. None of the standard methods like ModifySystemSettings or ModifyVirtualSystem of Msvm_VirtualSystemSnapshotService or Msvm_VirtualSystemManagementService has been helpful so far.
Powershell Rename-VMSnapshot可以完成这项工作,但是我不确定它是否在使用WMI.
Powershell Rename-VMSnapshot can do the job however I am not sure it is using WMI.
有什么主意吗?
推荐答案
这对我有用:
//
// Rename last snapshot to desired name
//
using (ManagementBaseObject inParams = vmms.GetMethodParameters("ModifySystemSettings"))
{
ManagementObject setting = null;
ManagementObjectCollection settings = vm.GetRelated(
"Msvm_VirtualSystemSettingData",
"Msvm_MostCurrentSnapshotInBranch",
null,
null,
"Dependent",
"Antecedent",
false,
null
);
foreach (ManagementObject instance in settings)
{
// Usually only one, but loop through to the end to get latest one
if (setting != null)
{
if (string.Compare(
(string)instance["CreationTime"],
(string)setting["CreationTime"],
true) > 0
)
{
// Get latest one since there could be duplicates
setting = instance;
}
}
else
{
setting = instance;
}
}
setting["ElementName"] = snapshotName;
inParams["SystemSettings"] = setting.GetText(TextFormat.WmiDtd20);
using (ManagementBaseObject outParams = vmms.InvokeMethod("ModifySystemSettings", inParams, null))
{
// What this does is get Job managementObject and check JobState to be JobCompleted.
this.ProcessSnapshotMethodResult(outParams, "rename");
}
}
这篇关于从C#重命名Hyper-V WMI V2中的快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文