DeleteFileW returns incorrect error code in Vista for DLLs

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,

I've found what seems to be a bug in the DeleteFileW function in Vista, I was just wondering if this was known about already:

It seems that DeleteFileW can return an incorrect error code when attempting to delete a DLL that is in use, _if elevation is used_.

For example, deleting an in-use DLL from the Program Files folder. Normally this would return ERROR_SHARING_VIOLATION, however because elevation is needed, ERROR_ACCESS_DENIED is return. This is fine, but if elevation permission is then granted and the delete is tried again, ERROR_ACCESS_DENIED is still returned.

You can demonstrate this quite easily using a DOS prompt. First, a non-admin DOS prompt:

C:\Program Files\MSN Messenger>del msnmsgr.exe
C:\Program Files\MSN Messenger\msnmsgr.exe
Access is denied.

C:\Program Files\MSN Messenger>del msgsres.dll
C:\Program Files\MSN Messenger\msgsres.dll
Access is denied.


These are the expected results. However, with an administrator DOS prompt, the results are surprising:

C:\Program Files\MSN Messenger>del msgsres.dll
C:\Program Files\MSN Messenger\msgsres.dll
Access is denied.

C:\Program Files\MSN Messenger>del msnmsgr.exe
C:\Program Files\MSN Messenger\msnmsgr.exe
The process cannot access the file because it is being used by another process.


As you can see, the correct error code is returned for the .exe, but the ..dll error code is wrong (even though both files are in use.)

In XP, or in the case of in-use files in Vista for which elevation is not needed in order to delete them, ERROR_SHARING_VIOLATION is returned for both EXEs and DLLs.

Can anyone confirm this?

Cheers,
Jon


.



Relevant Pages

  • Re: DeleteFileW returns incorrect error code in Vista for DLLs
    ... I've found what seems to be a bug in the DeleteFileW function in Vista, ... attempting to delete a DLL that is in use, _if elevation is used_. ... deleting an in-use DLL from the Program Files folder. ...
    (microsoft.public.win32.programmer.kernel)
  • RE: WinVerifyTrust Failure on WinXP
    ... it will work on all Vista platforms: this is a well know stability issue on ... //return itvWintrustNotOnMachine; ... PFnWTHelperProvDataFromStateData pfnWTHelperProvDataFromStateData= ... because this may create dependency loops in the DLL load order. ...
    (microsoft.public.platformsdk.security)
  • Re: DeleteFileW returns incorrect error code in Vista for DLLs
    ... MSN Messenger was just an example, we actually discovered this problem with our own software when trying to replace an in-use DLL. ... Our software offers to schedule a replacement at reboot if it gets an ERROR_SHARING_VIOLATION, and it appeared in testing that this was only failing on Vista under UAC - it works fine on XP, and it works fine on Vista in locations that do not require elevation. ... I just tested this on an XP system, and attempting to delete an in-use DLL from the Program Files folder gives the "sharing violation" error. ... Microsoft Online Community Support ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Strange dll problem
    ... I have a strange problem with my app and I can't find a solution. ... Windows XP and Windows Vista. ... dll and a static lib, ... with the Unicode build of the Codex library, so I tried a non-Unicode ...
    (microsoft.public.vc.mfc)
  • Re: Vista and VB6 DLL
    ... there are some pretty cool things in vista that a lot of people don't know ... The first thing I did after installing Vista was to turn off the UAC. ... Pearson Software Consulting ... When you compile an ActiveX DLL in VB6, ...
    (microsoft.public.excel.programming)