/// <summary> /// Unsurfaces (detaches) a virtual hard disk (VHD) by locating an appropriate VHD provider to accomplish the operation. /// </summary> public void Detach( DETACH_VIRTUAL_DISK_FLAG flags = DETACH_VIRTUAL_DISK_FLAG.DETACH_VIRTUAL_DISK_FLAG_NONE) { if (!IsAttached) { return; } var ret = NativeMethods.DetachVirtualDisk(CheckDisposed(), flags, 0); switch (ret) { case NativeMethods.ERROR_NOT_FOUND: // There's nothing to do here. The device wasn't found, which means there's a // really good chance that it wasn't attached to begin with. // And, since we were asked to detach it anyway, we can assume that the system // is already in the desired state. case NativeMethods.ERROR_SUCCESS: break; default: throw new Win32Exception(ret); } }
public static extern int DetachVirtualDisk(IntPtr virtualDiskHandle, DETACH_VIRTUAL_DISK_FLAG flags, Int32 providerSpecificFlags);
public static extern Int32 DetachVirtualDisk(VirtualDiskSafeHandle VirtualDiskHandle, DETACH_VIRTUAL_DISK_FLAG Flags, Int32 ProviderSpecificFlags);
public static extern uint DetachVirtualDisk(IntPtr Handle, DETACH_VIRTUAL_DISK_FLAG Flag, uint ProviderSpecificFlags);