static void Main(string[] args) { VirtualStorageType storageType = new VirtualStorageType(); storageType.DeviceId = VirtualStorageDeviceTypes.Vhdx; storageType.VendorId = VirtualStorageType.VendorIdMicrosoft; VirtualDiskSafeHandle diskHandle = new VirtualDiskSafeHandle(); string filename = @"C:\temp\test.vhdx"; OpenVirtualDiskParameters readParameters = new OpenVirtualDiskParameters(); readParameters.Version = OpenVirtualDiskVersions.Version2; readParameters.Version2 = new OpenVirtualDiskParametersVersion2() { GetInfoOnly = false, ReadOnly = false, ResiliencyGuid = Guid.Empty, }; uint result = VirtualDiskApi.OpenVirtualDisk(storageType, filename, VirtualDiskAccessMasks.None, OpenVirtualDiskFlags.None, readParameters, diskHandle); RawSecurityDescriptor descriptor = new RawSecurityDescriptor("O:BAG:BAD:(A;;GA;;;WD)"); AttachVirtualDiskParameters parameters = new AttachVirtualDiskParameters(); parameters.Version = AttachVirtualDiskVersions.Version1; result = VirtualDiskApi.AttachVirtualDisk(diskHandle, descriptor, AttachVirtualDiskFlags.PermanentLifetime, 0, parameters, null); diskHandle.Close(); diskHandle = null; }
public static extern Int32 OpenVirtualDisk(ref VIRTUAL_STORAGE_TYPE VirtualStorageType, String Path, VIRTUAL_DISK_ACCESS_MASK VirtualDiskAccessMask, OPEN_VIRTUAL_DISK_FLAG Flags, ref OPEN_VIRTUAL_DISK_PARAMETERS Parameters, ref VirtualDiskSafeHandle Handle);
public static extern Int32 GetVirtualDiskPhysicalPath(VirtualDiskSafeHandle VirtualDiskHandle, ref Int32 DiskPathSizeInBytes, StringBuilder DiskPath);
public static extern Int32 GetVirtualDiskOperationProgress(VirtualDiskSafeHandle VirtualDiskHandle, ref NativeOverlapped Overlapped, ref VIRTUAL_DISK_PROGRESS Progress);
public static extern Int32 GetVirtualDiskInformation(VirtualDiskSafeHandle VirtualDiskHandle, ref Int32 VirtualDiskInfoSize, ref GET_VIRTUAL_DISK_INFO VirtualDiskInfo, ref Int32 SizeUsed);
public static extern Int32 DetachVirtualDisk(VirtualDiskSafeHandle VirtualDiskHandle, DETACH_VIRTUAL_DISK_FLAG Flags, Int32 ProviderSpecificFlags);
public static extern Int32 CreateVirtualDisk(ref VIRTUAL_STORAGE_TYPE VirtualStorageType, String Path, VIRTUAL_DISK_ACCESS_MASK VirtualDiskAccessMask, IntPtr SecurityDescriptor, CREATE_VIRTUAL_DISK_FLAG Flags, Int32 ProviderSpecificFlags, ref CREATE_VIRTUAL_DISK_PARAMETERS Parameters, ref NativeOverlapped Overlapped, ref VirtualDiskSafeHandle Handle);
public static extern Int32 AttachVirtualDisk(VirtualDiskSafeHandle VirtualDiskHandle, IntPtr SecurityDescriptor, ATTACH_VIRTUAL_DISK_FLAG Flags, Int32 ProviderSpecificFlags, ref ATTACH_VIRTUAL_DISK_PARAMETERS Parameters, IntPtr Overlapped);
public static extern Int32 OpenVirtualDisk(ref VIRTUAL_STORAGE_TYPE VirtualStorageType, string Path, VIRTUAL_DISK_ACCESS_MASK VirtualDiskAccessMask, OPEN_VIRTUAL_DISK_FLAG Flags, ref OPEN_VIRTUAL_DISK_PARAMETERS Parameters, ref VirtualDiskSafeHandle Handle);
public static extern Int32 SetVirtualDiskInformation(VirtualDiskSafeHandle VirtualDiskHandle, ref SET_VIRTUAL_DISK_INFO VirtualDiskInfo);
private VirtualHardDisk2(string filename, VirtualDiskSafeHandle handle) : base(filename, handle) { }
public static extern Int32 MergeVirtualDisk(VirtualDiskSafeHandle VirtualDiskHandle, MERGE_VIRTUAL_DISK_FLAG Flags, ref MERGE_VIRTUAL_DISK_PARAMETERS Parameters, IntPtr Overlapped);
public static extern Int32 GetStorageDependencyInformation(VirtualDiskSafeHandle ObjectHandle, GET_STORAGE_DEPENDENCY_FLAG Flags, Int32 StorageDependencyInfoSize, ref STORAGE_DEPENDENCY_INFO StorageDependencyInfo, ref Int32 SizeUsed);
public static extern Int32 ExpandVirtualDisk(VirtualDiskSafeHandle VirtualDiskHandle, EXPAND_VIRTUAL_DISK_FLAG Flags, ref EXPAND_VIRTUAL_DISK_PARAMETERS Parameters, IntPtr Overlapped);
public static extern Int32 CompactVirtualDisk(VirtualDiskSafeHandle VirtualDiskHandle, COMPACT_VIRTUAL_DISK_FLAG Flags, ref COMPACT_VIRTUAL_DISK_PARAMETERS Parameters, IntPtr Overlapped);
protected VirtualHardDiskBase(string filename, VirtualDiskSafeHandle handle) : base(filename, handle) { }