RE: Vista Undeletable File Problem



Please understand that FileDelete retursn TRUE (ie. it acknowledges that the
file deleted) - and it WILL be deleted as soon as all handles are closed. The
system cannot delete a file while it has open handles - but it allows you to
INITIATE the delete operation.

My "constructive" advice was to check that you did release the DLL
(FreeLibrary). If you do that then it's the system (Vista) which still keeps
a handle to the file.
My other "constructive" advice was that if you create with delete-on-close
than you don't even have to worry about this issue.

Laszlo Elteto
SafeNet, Inc.

"cyril macdonald" wrote:

Please don't post unless you have constructive comments.

This issue occurs only on Vista, and if I delete a file, and FileDelete
returns true, then it should be deleted.

"lelteto" wrote:

Windows just tries to "keep around" the DLL ebcause you used it recently in
the app. Did you unload the DLL? Even if yes, Windows waits a while in the
assumption that you may want to use it again.

The reason you see this behavior has nothing to do with Vista. It's the
behavior with OPEN files. Windows allows you delete an open file - but the
delete operation will actually be done only when all handles to the file is
closed. Since Windows keeps the DLL open (as I said, assuming you may want to
use it again - it's just optimization to avoid unnecessary expensive opens)
it is not deleted until you close the application - at which point Windows
also closes the handle to it and the file is really deleted.

I wouldn't worry about this. The best way to handle these kind of files is
to create it with "delete-on-close" flag, then you don't even have to call
the delete function. (An added benefit is that even if your application
crashes the file still will be deleted.)

Laszlo Elteto
SafeNet, Inc.

"cyril macdonald" wrote:


I have a high integrity process which creates a DLL in the Program Files
folder. I delete the DLL when I am done with it, and the DeleteFile function
returns true.

However, If I then iterate through the files with FindFirstFile/FindNextFile
within my app, I see the file is still there. If I try to delete it again
(using DeleteFile), I get "access denied" error code.

If I go in explorer and try to delete the file, it deletes successfully,
however if I refresh explorer, the file returns immediately.

If I check the security attributes of the file in explorer, this operation
is denied even after I escalate privileges through the UAC dialog. I can't
take ownership of the file either (even as admin).

When my application terminates, the DLL is automatically deleted.

Does anyone know what might be causing this behaviour? Is this
virtualisation run amok? I tried disabling virtualisation in my process
token, but this appears to have had no effect.
.



Relevant Pages

  • RE: Vista Undeletable File Problem
    ... Did you unload the DLL? ... behavior with OPEN files. ... Windows allows you delete an open file - but the ... I delete the DLL when I am done with it, and the DeleteFile function ...
    (microsoft.public.platformsdk.security)
  • Re: FreeLibrary() and DeleteFile() Windows APIs functions
    ... I before have forget to write that I call the FreeLibraryfrom my_DllMaindetach. ... But I have traced the other_DllMaindetach and it is called befor I do DeleteFile() from my_DllMain, because for try I have put a sleep of 20000 ms between FreeLibraryand DeleteFile. ... > Process Explorer but you may have missed a client process. ... > search the DLL by name by using the Search feature of Process Explorer? ...
    (microsoft.public.win32.programmer.kernel)
  • Re: DeleteFile fails after FreeLibrary
    ... > I have some DLL thats should be unloaded and deleted by request. ... but when i try to do DeleteFile(pszDLLName) it ... Set a breakpoint on your call to DeleteFile and then check if the dll is ...
    (microsoft.public.win32.programmer.kernel)
  • Re: DeleteFile fails after FreeLibrary
    ... I've try to FreeLibrary(GetModuleHandle (pszDLLName)). ... fails and GetLastError reopts that access is denied to this file. ... Set a breakpoint on your call to DeleteFile and then check if the dll is ... make sure the dll is not read-only. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: IPC resource access counting problem
    ... InterlockedIncrement to increment the value, not ++!), program B opens and ... remove its process ID and decrement count ... construction decrements the counter, each destruction increments it. ... BTW DeleteFile is documented as dodgy: ...
    (microsoft.public.vc.mfc)