How to set filename for zwcreatefile function?

Viewed 129

Suppose I want to open file c:/test.txt That's how I do it at the moment, and it does not work:

RtlInitUnicodeString(&uniName, L"\\SystemRoot\\test.txt");  // 
    InitializeObjectAttributes(&obj_atr, &uniName,
        OBJ_CASE_INSENSITIVE /*| OBJ_KERNEL_HANDLE*/,
        NULL, NULL);
 ntStatus = ZwCreateFile(&handle,
            GENERIC_WRITE,
            &obj_atr, &result, NULL,
            FILE_ATTRIBUTE_NORMAL,
            0,
            FILE_OPEN,
            FILE_SYNCHRONOUS_IO_NONALERT,
            NULL, 0);
1 Answers

According to this page, "The \SystemRoot namespace is mapped to the folder where the operation system is installed. For example, this folder may be C:\Windows or D:\Winnt."

So L"\\SystemRoot\\test.txt" will map to C:\Windows\test.txt and not C:\test.txt.

Alternatively, you can try L"\\DosDevices\\C:\\test.txt", but the same page notes that, "If the device driver is loaded early, the \DosDevices namespace may not yet exist."

Related