Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results


Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging

The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.

Check out The OSR Learning Library at:

CreateFile Vs DuplicateHandle [and IRP_MJ_CREATE]

ajitabhsajitabhs Member Posts: 100

Hi All,
Just want to confirm (and refresh) my understanding about this. lets say that there are two processes. Process A and Process B. Process A opens a handle to a device, the driver gets IRP_MJ_CREATE call.

  1. Then process B calls DuplicateHandle API to create a copy for it's use.

    In my understanding when process B calls DuplicateHandle, the driver will NOT get a notification at all (IRP_MJ_CREATE will not get called). Just the reference count on the handle will get incremented. Is this correct?

  2. Process B is done with the handle and it calls CloseHandle (on the "duplicate" handle).

    This will NOT result in a call to IRP_MJ_CLOSE, since the reference count on the handle is still not zero (Process A still has it). Is this correct?

  3. After Process B closed the handle (step-2 above) the process A also closes the handle.

    This call will result in call to IRP_MJ_CLOSE, as now the reference count on the object is zero.

Is this understanding correct?

Please let me know. Appreciate the time.

  • Aj


  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,650
    This is correct if you replace “reference count” with “HANDLE count” and “IRP_MJ_CLOSE” with “IRP_MJ_CLEANUP”


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 13-17 May 2024 Live, Online
Developing Minifilters 1-5 Apr 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 26 Feb - 1 Mar 2024 Live, Online