Re: Telling if a DLL is in use

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



First make a copy of the .dll, then rename the original to something-else,
then try to delete the something-else.

If the renamed-original failed to delete, then it is in use. You can rename
it back to the original name, and delete the copy, and return IN-USE (to
skip trying to delete it).

If the renamed-original deleted successfully, then it was not in use. you
still have the copy, and you can return NOT-IN-USE, and that will continue
to be true (because now there is no file with the original name, just the
copy).

Deleting the file before attempting to delete it may seem to violate your
requirement that you detect in-use before attempting deletion, but it is the
only way to get a detection-routine whose return-value is not potentially
immediately obsolete.

If you return (const char*) 0 for IN-USE, and (const char*) "name-of-copy",
then your detection routine works properly, with the unavoidable side-effect
of making you work with a name-of-copy if it was NOT-IN-USE. But, since you
know the filename you gave the detection routine, and it gives you the name
of the copy, you can rename it back to the original if you decide to not
delete it.





"Rich S." <RichS@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3F624DCE-D443-4ECE-A9EA-D5C3FAF6F1AD@xxxxxxxxxxxxxxxx
> Hello,
>
> I need to be able to tell if a DLL is in use before I attempt to delete it
> and replace it with a newer version.
>
> For some reason, Windows is allowing me to call MoveFile(OldDLL, NewDLL)
> on
> the DLL even when it is in use! What's more, it even allows me to copy a
> new
> DLL into its place! The only thing it does not allow is calling
> DeleteFile.
>
> Is this because I am a member of the DEBUGGING group on XP that I am able
> to
> do this?
>
> Is there a better way to tell if a DLL is in use rather than relying on
> receiving an error message when renaming or deleting the DLL?
>
> Thank you very much,
> Rich


.



Relevant Pages

  • Re: Riched20.dll
    ... It can come from a folder ... you may have on the system called ServicePackFiles. ... Rename in ServicePackFiles ... > dll and paste the new one, the current dll after the rename is back. ...
    (microsoft.public.windowsxp.general)
  • Re: Renaming DLLs?
    ... The application still looks for the original filename. ... Yes, you can rename ... a dll, though obviously, the app that uses it has to know about the ... This is taken from a larger script I use with some apps that lets ...
    (comp.os.os2.programmer.misc)
  • Re: Deploying/Development without Visual Studio
    ... So should I use those under Platform Builder 4.2 or use the ones ... > from the CF Framework cab files? ... To rename .cab CF dll you can load thi files into Reflector and it will ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: detecting a JVM embedded in an app?
    ... >In message, George Neuner ... >>lib file was edited or regenerated to reference the renamed DLL. ... >I've never known any company rename another company's DLLs. ... >Probably violates the license agreement in the first place. ...
    (comp.lang.java.softwaretools)
  • Re: Preventing XP from restoring a dll
    ... >reboot, apparently to remove the dll from memory. ... >something keeps restoring the original dll as soon as I rename it. ... Windows\ServicePackFiles if you installed a service Pack. ...
    (microsoft.public.windowsxp.general)