public static VirtualHardDisk Open(string filename, VirtualDiskAccessMasks accessMask = VirtualDiskAccessMasks.All, OpenVirtualDiskFlags flag = OpenVirtualDiskFlags.None, uint rwDepth = 0) { var storageType = new VirtualStorageType(); var parameters = new OpenVirtualDiskParameters { Version = OpenVirtualDiskVersions.Version1, Version1 = new OpenVirtualDiskParametersVersion1 { RWDepth = rwDepth} }; var handle = VirtualDiskCore.OpenVirtualDisk(storageType, filename, accessMask, flag, parameters); var vhd = new VirtualHardDisk(filename, handle); // ReSharper disable once InvertIf if (vhd.VirtualStorageType.DeviceId == VirtualStorageDeviceTypes.Iso) { vhd.Dispose(); throw new NotSupportedException("This class does not support ISO files."); } return vhd; }
public static VirtualHardDisk2 Open(string filename, OpenVirtualDiskFlags flag = OpenVirtualDiskFlags.None, bool getInfoOnly = false, bool readOnly = false, Guid resiliencyGuid = default(Guid)) { var storageType = new VirtualStorageType(); var parameters = new OpenVirtualDiskParameters { Version = OpenVirtualDiskVersions.Version2, Version2 = new OpenVirtualDiskParametersVersion2 { GetInfoOnly = getInfoOnly, ReadOnly = readOnly, ResiliencyGuid = resiliencyGuid } }; // When using OpenVirtulaDiskVersions.Version2, VirtualDiskAccessMasks *must* be set to None var handle = VirtualDiskCore.OpenVirtualDisk(storageType, filename, VirtualDiskAccessMasks.None, flag, parameters); var vhd = new VirtualHardDisk2(filename, handle); // ReSharper disable once InvertIf if (vhd.VirtualStorageType.DeviceId == VirtualStorageDeviceTypes.Iso) { vhd.Dispose(); throw new NotSupportedException("This class does not support ISO files."); } return vhd; }