CreateManagedFile
This function creates a new file or opens an existing one, with advanced management options.
Parameters
| Parameter | Type | Description |
|---|---|---|
lpFileName |
LPCWSTR |
The name of the file to be created or opened. |
dwDesiredAccess |
DWORD |
The requested access to the file. For a list of common values, see File Access Rights. |
dwShareMode |
DWORD |
A bitmap of the usage type that the process has for the file. For a list of common values, see File Sharing. |
lpSecurityAttributes |
LPSECURITY_ATTRIBUTES |
A pointer to a SECURITY_ATTRIBUTES structure that contains the security descriptor for the file. If this parameter is NULL, the file will have a default security descriptor. |
dwCreationDisposition |
DWORD |
An action to take if a file that matches the name specified by lpFileName exists and what to do if it does not exist. This parameter can be one of the following values:
|
dwFlagsAndAttributes |
DWORD |
The file attributes and flags for the file. For a list of common values, see File Attributes. |
hTemplateFile |
HANDLE |
A handle to a template file with the desired security attributes and flags. The CreateManagedFile function uses the security attributes of the template file to provide security for the new file. |
dwManageOptions |
DWORD |
Additional options for file management. This can include flags such as:
|
Return Value
Success
If the function succeeds, the return value is an open handle to the specified file with the requested access, share mode, and creation disposition. The handle has the GENERIC_READ, GENERIC_WRITE, or both access rights based on the dwDesiredAccess parameter.
If dwCreationDisposition is OPEN_ALWAYS and the file already exists, the function returns an open handle to the existing file.
If dwCreationDisposition is CREATE_ALWAYS and the file exists, the function truncates the file to zero bytes and returns an open handle to the file.
Failure
If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.
Remarks
The CreateManagedFile function is an enhanced version of CreateFile, providing integrated support for advanced file management features like compression, encryption, and quota tracking.
Note: The dwManageOptions parameter introduces new capabilities. Ensure your system supports these features before using them. Consult the specific API documentation for details on compatibility and prerequisites.
Use the CloseHandle function to close the file handle when you are finished with it.
Requirements
| Attribute | Value |
|---|---|
| Minimum supported client | Windows 10, version 1809 |
| Minimum supported server | Windows Server 2019 |
| Target Platform | Windows |
| Header | fileapi.h |
| Library | Kernel32.lib |
| DLL | Kernel32.dll |