Msvm_MountedStorageImage 类的 DetachVirtualHardDisk 方法
分离与此类关联的已装载存储映像。
语法
uint32 DetachVirtualHardDisk();
参数
此方法没有任何参数。
返回值
类型: uint32
此方法可以返回以下值之一。
-
成功 (0)
-
失败 (1)
备注
UAC 筛选可能会限制对 Msvm_MountedStorageImage 类的访问。 有关详细信息,请参阅 用户帐户控制和 WMI。
示例
以下 C# 示例演示如何分离虚拟硬盘文件。 可以在 V2) (虚拟化示例的常用实用工具 中找到引用的实用工具。
public static void DetachVirtualHardDisk(string path)
{
ManagementScope scope = new ManagementScope(@"root\virtualization\V2", null);
ManagementClass mountedStorageImageServiceClass = new ManagementClass("Msvm_MountedStorageImage");
mountedStorageImageServiceClass.Scope = scope;
using (ManagementObjectCollection collection = mountedStorageImageServiceClass.GetInstances())
{
foreach (ManagementObject image in collection)
{
using (image)
{
string name = image.GetPropertyValue("Name").ToString();
if (string.Equals(name, path, StringComparison.OrdinalIgnoreCase))
{
ManagementBaseObject outParams = image.InvokeMethod("DetachVirtualHardDisk", null, null);
if ((UInt32)outParams["ReturnValue"] == 0)
{
Console.WriteLine("{0} was detached successfully.", path);
}
else
{
Console.WriteLine("Unable to dettach {0}", path);
}
outParams.Dispose();
break;
}
image.Dispose();
}
}
}
}
要求
要求 | 值 |
---|---|
最低受支持的客户端 |
Windows 8 [仅限桌面应用] |
最低受支持的服务器 |
Windows Server 2012 [仅限桌面应用] |
命名空间 |
Root\Virtualization\V2 |
MOF |
|
DLL |
|
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈