Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3601178
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:35:20+00:00 2026-05-18T20:35:20+00:00

When we create a file by CreateFile, the file created and we get the

  • 0

When we create a file by CreateFile, the file created and we get the handle.
But CreateDirectory doesn’t return directory’s handle.

I’d like to also get the handle when I create a directory.
I want to handle this by issuing only one I/O request packet.

So, ‘Do CreateDirectory, then CreateFile with FILE_FLAG_BACKUP_SEMANTICS.’ won’t be an answer.
It will issue two Irps to file system.

Is there an Api I can use in Usermode(Win32 Api)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:35:21+00:00Added an answer on May 18, 2026 at 8:35 pm

    NT can do this, but Win32 doesn’t expose it. You need to use NT APIs for this. NtCreateFile, specifically. It should follow the same parameters of ZwCreateFile.

    Here’s an illustrative example (hacked up 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 things to note…

    • NT paths have slightly different conventions than Win32 paths… You might have to sanitize the path.

    • When talking about HANDLEs, NT APIs generally deal with NULL rather than INVALID_HANDLE_VALUE.

    • I didn’t do it here, but by changing the InitializeObjectAttributes call you can do interesting things, like do a create relative to another directory handle. Of course all the flags I’ve put in here you might also want to change. Consult documentation and/or the web for best results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am calling CreateFile() to create a file in the Program Data directory. I'm
How can I create this file in a directory in windows 2003 SP2: .hgignore
I want to create a file using C++, but I have no idea how
I create a file in JavaScript. Now I want to be able to make
How do I create a file-like object (same duck type as File) with the
I want to create a file on the webserver dynamically in PHP. First I
I want to create XML file from my Excel file through .NET (c#). My
I want to create a file that only resides in memory... In looking through
Create a file called Valid[File].txt and stick some text in it. Start powershell and
I need to replace all WinAPI calls of the CreateFile, ReadFile, SetFilePointer, CloseHandle with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.