NT can do this, but Win32 does not open it. For this you need to use the NT API. NtCreateFile in particular. It must follow the same ZwCreateFile parameters.
Here is an illustrative example (hacked in a hurry inside a web form - YMMV):
HANDLE CreateDirectoryAndGetHandle(PWSTR pszFileName) { NTSTATUS Status; UNICODE_STRING FileName; HANDLE DirectoryHandle; IO_STATUS_BLOCK IoStatus; OBJECT_ATTRIBUTES ObjectAttributes; RtlInitUnicodeString(&FileName, pszFileName); InitializeObjectAttributes(&ObjectAtributes, &FileName, 0, NULL, NULL); Status = NtCreateFile(&DirectoryHandle, GENERIC_READ | GENERIC_WRITE, &ObjectAttributes, &IoStatus, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_CREATE, FILE_DIRECTORY_FILE, NULL, 0); if (NT_SUCCESS(Status)) { return DirectoryHandle; } else { SetLastError(RtlNtStatusToDosError(Status)); return INVALID_HANDLE_VALUE; } }
Some notes ...
NT paths have slightly different conventions than Win32 paths ... You may need to sanitize the path.
Speaking of HANDLE s, NT APIs usually deal with NULL , not INVALID_HANDLE_VALUE .
I did not do this here, but by changing the call to InitializeObjectAttributes , you can do interesting things, for example, create relative to another directory descriptor. Of course, you can also change all the flags that I added here. For best results, refer to the documentation and / or website.
source share