Wednesday, April 9, 2008

What the Heck is Locking my .DLL?

This is a problem that comes up often enough to be a real PITA, but infrequently enough that you'll probably forget how to solve it. Hopefully a quick Google search will find this post and save you a little time.

Before you read on, I think it's only fair to warn you. I can only ensure that this works on Windows XP. I understand it does not on Windows 2000. I haven't tried it on any other system.

So, here' the scenario. You have a .DLL on your system that you want to delete. For stability's sake, we'll assume it's one you created. You find it via Windows Explorer, select it and hit the delete key....you wait...and then you get a message stating you can't delete the file because it's in use.

In use. What do you mean in use? It's my own .DLL and I'm not using it!

Your first step will undoubtedly be the trusty Task Manager. Your plan is to find the .DLL and kill it from there.

No joy. It's not listed. Now what?

In walks Task Manager's big brother. It's that bad boy, tasklist.exe, the command line version of Task Manager. With one simple command, you'll know exactly what is locking your .DLL. Just open a command window and type the following:

tasklist /m YourDllName.dll

This will list the "images" that have locks on your module. In addition it lists their pid.

You're most likely going to see that this is a dllhost.exe holding onto your .DLL. Armed with this information, you can now use your trusty Task Manager, find the dllhost.exe with the pid of the offender, and kill, kill, kill!

2 comments:

Justin said...

Yeah but what about when it's devenv.exe that's locking your dll? Then what do you do?? :(

Bill said...

deven.exe is Visual Studio. If you have any Visual Studio windows open, try closing them and accessing your dll again.