Getting wrong information on using STATUS_ACCESS_DENIED in windows 7

I used the macro STATUS_ACCESS_DENIED for my code to avoid renaming in LOCAL SHARED folder
but i am getting the wrong information
when i try to rename a folder which is LOCAL SHARED
it gives me a pop up FOLDER IN USE rather than ACCESS DENIED
this works fine for win xp but it gives problem in win 7

In IRP_MJ_SET_INFORMATION - filerenameinformation - we are returning STATUS_ACCESS_DENIED for renaming a folder which is locally shared in our driver code,
but we expect user should get same “access denied” but we are getting “folder in use”. this is from win 7,
but win xp has "access denied " prompted to user.
So , i want the same message for win 7 too.
Can you please help me which macro i should use so that i may get “Access Denied” while renaming a folder which is locally shared.

You should always return the error status that most accurately describes the error condition. In your case that’s STATUS_ACCESS_DENIED. What upper levels of the system do with that is not up to you, nor should you try to second-guess what they’ll do. Besides, your filter can’t guarantee that the shell, and only the shell, will be the entity sending the FileRenameInformation.

I suspect the shell in Win7 makes extra checks after getting STATUS_ACCESS_DENIED from a rename. It probably checks the ACLs on the folder. If the caller has DELETE access (necessary for a rename), the shell assumes the STATUS_ACCESS_DENIED resulted from the file system finding open files/folders under the folder being renamed. If the caller doesn’t have DELETE access, the shell instead displays an “access denied” dialog. All of this is an attempt to provide more information to the user so he can take some corrective action.

To verify this you could watch for IRP_MJ_QUERY_SECURITY after you return STATUS_ACCESS_DENIED for a folder rename. If it’s the shell sending it, then my theory is likely right.

Christian [MSFT]
This posting is provided “AS IS” with no warranties, and confers no rights.