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 |
|