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

RawDisk.CreateFile method


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



Opens raw access to the file being locked by other process or inaccessible in other way due to security constraints


    class function CreateFile( FileName : WideString; DesiredAccess : DWORD; CreationDisposition : DWORD; FlagsAndAttributes : DWORD; LicenseKey : WideString) : THandle;

[C++ (DLL/Lib)]
    static HANDLE CreateFile( unsigned short* FileName, unsigned long DesiredAccess, unsigned long CreationDisposition unsigned long FlagsAndAttributes, unsigned short* LicenseKey);

[C++ (VCL)]
    static THandle __fastcall CreateFile( WideString FileName, unsigned long DesiredAccess, unsigned long CreationDisposition, unsigned long FlagsAndAttributes, WideString LicenseKey);

[C++ (.NET)]
    static IntPtr CreateFile( String^ FileName, long DesiredAccess, long CreationDisposition, long FlagsAndAttributes, String^ LicenseKey);

    static IntPtr CreateFile( string FileName, int DesiredAccess, int CreationDisposition, int FlagsAndAttributes, string LicenseKey)

    Shared Function CreateFile( ByVal FileName As String, ByVal DesiredAccess As Integer, ByVal CreationDisposition As Integer, ByVal FlagsAndAttributes As Integer, ByVal LicenseKey As String) As IntPtr


  • FileName - The name of the file to be created or opened.
  • DesiredAccess - Desired access, eg. GENERIC_READ | GENERIC_WRITE. The constants are defined in Windows API
  • CreationDisposition - Any set of constants, used in dwCreationDisposition parameter of CreateFile() function in Windows API.
  • FlagsAndAttributes - Any set of constants, used in dwFlagsAndAttributes parameter of CreateFile() function 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.

Return values

The handle of the device.


Use this method to open the file and obtain it's handle. The method is useful when the file is exclusively opened by some other process or when your code doesn't have enough security rights or permissions to access this file in a standard way (using CreateFile() function in Windows API). The obtained handle must be used with ReadFile() and WriteFile() functions of Windows API.

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

The constants for DesiredAccess, CreationDisposition and FlagsAndAttributes parameters can be found in the description of CreateFile() function of Windows API in MSDN Library.

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

Back to top