RawDisk

Direct access to disks and protected files from user-mode applications in Windows

RawDisk.OpenEx method

Filter:

Pascal    C++ (DLL/Lib)    C++ (VCL)    C++ (.NET)    C#    VB.NET   

RawDisk     See also    

Overview

Opens raw access to the volume, unmounts the volume and returns the volume handle

Declaration

[Pascal]
    class function OpenEx( DeviceName : WideString; DesiredAccess : DWORD; LicenseKey : WideString; ForceUnmount : boolean; var UnmountFailed : boolean ) : THandle;

[C++ (DLL/Lib)]
    static HANDLE Open( unsigned short* DeviceName, unsigned long DesiredAccess, unsigned short* LicenseKey, BOOL ForceUnmount, BOOL* UnmountFailed );

[C++ (VCL)]
    static THandle __fastcall Open( WideString DeviceName, unsigned long DesiredAccess, WideString LicenseKey, bool ForceUnmount, bool &UnmountFailed );

[C++ (.NET)]
    static IntPtr OpenEx( String^ DeviceName, long DesiredAccess, String^ LicenseKey, bool ForceUnmount, bool %UnmountFailed );

[C#]
    static IntPtr OpenEx( string DeviceName, int DesiredAccess, string LicenseKey, bool ForceUnmount, ref bool UnmountFailed )

[VB.NET]
    Shared Function OpenEx( ByVal DeviceName As String, ByVal DesiredAccess As Integer, ByVal LicenseKey As String, ByVal ForceUnmount As Boolean, ByRef UnmountFailed As Boolean ) As IntPtr

Parameters

  • DeviceName - Required device name to open (with full path in the windows object namespace). Eg: "\??\C:" or "\??\PhysicalDrive0".
  • DesiredAccess - Desired access, eg. GENERIC_READ | GENERIC_WRITE. The constants are defined in Windows API
  • LicenseKey - The license key. RawDisk doesn't work without the license key (either production or evaluation). You can request the evaluation license key via request form.
  • ForceUnmount - This parameter specifies whether the device should be unmounted even when there are open files on this device.
  • UnmountFailed - On return the parameter specifies whether the device has been actually unmounted.

Return values

The handle of the device.

Description

Use this method to unmount and open the device. The obtained handle must be used with ReadFile(), WriteFile() and DeviceIoControl() functions of Windows API. Unmounting is strongly advised if you are going to to change the file system metadata (FAT, MFT tables etc) which can be accessed by the file system at the time of change.

Once you finished using the direct access to the device, call CloseHandle() Windows API function to release the resources.

The name of the device can be obtained using an utility, offered by Microsoft.
The constants for DesiredAccess parameter can be found in the description of CreateFile() function of Windows API in MSDN Library.

It can happen that unmounting fails (for example, if the disk contains pagefile or system files). If you have set ForceUnmount parameter to false and unmounting fails, then the function will return error. If you have set ForceUnmount to true and unmounting fails, the device is opened anyway, but UnmountFailed is set to true. It's recommended not to change any information on the device if unmounting failed, as such changes can corrupt the file system or just be lost.

If you don't plan to access file system metadata, it's recommended that you use Open method instead.

If the method fails for whatever reason, an exception with Windows-defined error code is thrown.

See also

Open    

Back to top