How do I delete a file which is locked by another process in C#?

Killing other processes is not a healthy thing to do. If your scenario involves something like uninstallation, you could use the MoveFileEx API function to mark the file for deletion upon next reboot.

If it appears that you really need to delete a file in use by another process, I’d recommend re-considering the actual problem before considering any solutions.

Leave a Comment