Reopens the specified file system object with different access rights, sharing mode, and flags.
HANDLE ReOpenFile( HANDLE hOriginalFile, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwFlagsAndAttributes );
A handle to the object to be reopened. The object must have been created by the CreateFile function.
The required access to the object. For a list of values, see File Security and Access Rights. You cannot request an access mode that conflicts with the sharing mode specified in a previous open request whose handle is still open.
If this parameter is zero (0), the application can query device attributes without accessing the device. This is useful if an application wants to determine the size of a floppy disk drive and the formats it supports without requiring a floppy in the drive.
The sharing mode of the object. You cannot request a sharing mode that conflicts with the access mode specified in a previous open request whose handle is still open.
If this parameter is zero (0) and CreateFile succeeds, the object cannot be shared and cannot be opened again until the handle is closed.
To enable other processes to share the object while your process has it open, use a combination of one or more of the following values to specify the type of access they can request when they open the object. These sharing options remain in effect until you close the handle to the object.
The file flags. This parameter can be one or more of the following values.
Indicates that the file is being opened or created for a backup or restore operation. The system ensures
that the calling process overrides file security checks, provided it has the
SE_BACKUP_NAME and SE_RESTORE_NAME privileges. For more
Changing Privileges in a Token.
You can also set this flag to obtain a handle to a directory. Where indicated, a directory handle can be passed to some functions in place of a file handle.
Indicates that the operating system is to delete the file immediately after all of its handles have been
closed, not just the specified handle but also any other open or duplicated handles.
Subsequent open requests for the file fail, unless FILE_SHARE_DELETE is used.
Instructs the system to open the file with no intermediate buffering or caching. When combined with
FILE_FLAG_OVERLAPPED, the flag gives maximum asynchronous performance, because the
I/O does not rely on the synchronous operations of the memory manager. However, some I/O operations take
longer, because data is not being held in the cache.
An application must meet specific requirements when working with files opened with FILE_FLAG_NO_BUFFERING:
An application can determine a volume sector size by calling the GetDiskFreeSpace function.
||Indicates that the file data is requested, but it should continue to reside in remote storage. It should not be transported back to local storage. This flag is intended for use by remote storage systems.|
||When this flag is used, normal reparse point processing does not occur, and ReOpenFile attempts to open the reparse point. When a file is opened, a file handle is returned, whether or not the filter that controls the reparse point is operational. This flag cannot be used with the CREATE_ALWAYS flag. If the file is not a reparse point, then this flag is ignored.|
Instructs the system to initialize the object, so that operations that take a significant amount of time to
process return ERROR_IO_PENDING. When the operation is finished, the specified event is set to the signaled
When you specify FILE_FLAG_OVERLAPPED, the file read and write functions must specify an OVERLAPPED structure. That is, when FILE_FLAG_OVERLAPPED is specified, an application must perform overlapped reading and writing.
When FILE_FLAG_OVERLAPPED is specified, the system does not maintain the file pointer. The file position must be passed as part of the lpOverlapped parameter (pointing to an OVERLAPPED structure) to the file read and write functions.
This flag also enables more than one operation to be performed simultaneously with the handle (a simultaneous read and write operation, for example).
||Indicates that the file is to be accessed according to POSIX rules. This includes allowing multiple files with names, differing only in case, for file systems that support such naming. Use care when using this option because files created with this flag may not be accessible by applications written for MS-DOS or 16-bit Windows.|
||Indicates that the file is accessed randomly. The system can use this as a hint to optimize file caching.|
Indicates that the file is to be accessed sequentially from beginning to end. The system can use this as a
hint to optimize file caching. If an application moves the file pointer for random access, optimum caching
may not occur; however, correct operation is still guaranteed.
Specifying this flag can increase performance for applications that read large files using sequential access. Performance gains can be even more noticeable for applications that read large files mostly sequentially, but occasionally skip over small ranges of bytes.
||Instructs the system to write through any intermediate cache and go directly to disk. The system can still cache write operations, but cannot lazily flush them.|
If the handle represents the client side of a named pipe, the dwFlags parameter can also contain Security Quality of Service information. For more information, see Impersonation Levels. When the calling application specifies the SECURITY_SQOS_PRESENT flag, the dwFlags parameter can contain one or more of the following values.
If the function succeeds, the return value is an open handle to the specified file.
If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.
The dwFlags parameter cannot contain any of the file attribute flags (FILE_ATTRIBUTE_*). These can only be specified when the file is created.
In Windows 8 and Windows Server 2012, this function is supported by the following technologies.
|Server Message Block (SMB) 3.0 protocol||Yes|
|SMB 3.0 Transparent Failover (TFO)||Yes|
|SMB 3.0 with Scale-out File Shares (SO)||Yes|
|Cluster Shared Volume File System (CsvFS)||Yes|
|Resilient File System (ReFS)||Yes|
|Minimum supported client||Windows Vista [desktop apps only]|
|Minimum supported server||Windows Server 2003 [desktop apps only]|
|Header||winbase.h (include Windows.h)|