Thursday, May 14, 2009

Determining which process has locked a .dll

Working in a windows environment I occasionally run into an issue with a .dll that I'm trying to delete being locked by another process. I see this frequently when trying to remove files from my target system before a clone. There are a couple of ways you can determine which process has the .dll locked. A quick command line way to do it is tasklist /m <.dll in question>.
For instance tasklist /m CORE40.dll.

If the .dll is locked I would see output such as the following:
Image Name PID Modules
========================= ======== ====================
msdtc.exe 1152 CORE40.dll

You can also check out Metalink Note 454040.1 for a script (prepatch.bat) that will identify similar information for you.