ZwDeleteFile routine
The ZwDeleteFile routine deletes the specified file.
Syntax
NTSTATUS ZwDeleteFile( _In_ POBJECT_ATTRIBUTES ObjectAttributes );
Parameters
- ObjectAttributes [in]
-
A pointer to an OBJECT_ATTRIBUTES structure that contains the attributes supplied by the caller to be used for the file object. These attributes would include the ObjectName and the SECURITY_DESCRIPTOR, for example. This parameter is initialized by calling the InitializeObjectAttributes macro.
Return value
ZwDeleteFile returns STATUS_SUCCESS or an appropriate error status representing the final completion status of the operation. Possible error status codes include the following:
| Return code | Description |
|---|---|
|
A temporary buffer required by this function could not be allocated. |
|
The specified ObjectAttributes parameter was a NULL pointer, not a valid pointer to an OBJECT_ATTRIBUTES structure, or some of the specified ObjectAttributes structure members were invalid. |
|
The ObjectAttributes parameter contained an ObjectName in the OBJECT_ATTRIBUTES structure that was invalid because an empty string was found after the OBJECT_NAME_PATH_SEPARATOR character. |
|
The ObjectAttributes parameter contained an ObjectName member in the OBJECT_ATTRIBUTES structure that could not be found. |
|
The ObjectAttributes parameter contained an ObjectName member in the OBJECT_ATTRIBUTES structure with an object path that could not be found. |
|
The ObjectAttributes parameter did not contain a RootDirectory member, but the ObjectName member in the OBJECT_ATTRIBUTES structure was an empty string or did not contain an OBJECT_NAME_PATH_SEPARATOR character. This indicates incorrect syntax for the object path. |
Remarks
ZwDeleteFile deletes the specified file object.
The ZwDeleteFile function is called after the InitializeAttributes macro is used to set attributes in the OBJECT_ATTRIBUTES structure for the file object to be deleted.
There are two alternate ways to specify the name of the file to be deleted with ZwDeleteFile:
-
As a fully qualified pathname, supplied in the ObjectName member of the input ObjectAttributes
-
As pathname relative to the directory file represented by the handle in the RootDirectory member of the input ObjectAttributes
Callers of ZwDeleteFile must be running at IRQL = PASSIVE_LEVEL and with special kernel APCs enabled.
Note If the call to the ZwDeleteFile function occurs in user mode, you should use the name "NtDeleteFile " instead of "ZwDeleteFile".
Requirements
|
Version | Available starting with Windows XP. |
|---|---|
|
Header |
|
|
Library |
|
|
IRQL | PASSIVE_LEVEL (see Remarks section) |
|
DDI compliance rules | PowerIrpDDis, HwStorPortProhibitedDDIs |
See also
Send comments about this topic to Microsoft
Build date: 5/22/2013