HOWTO Remove a File/Directory Lock from files/directories locked by other processes.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
HOWTO Remove a File/Directory Lock from files/directories locked by other processes.<br/><br/>Please help,<br/><br/>I want a way to force any process, with file/directory locks to have them removed.<br/><br/>Example. Process A has opened a file "MyFile.txt" with say WIN32 OpenFile, and is keeping the file handle returned opened.<br/><br/>I want a way to remove the file lock on "MyFile.txt", without killing Process A. Theoretically, if process A is in the middle of doing anything with the handle to "MyFile.txt", it should get an error/crash. This is actually very desireable for my needs.<br/><br/>I have long since made code to detect which processes have a file handle/lock to a file. using CreateToolhelp32Snapshot. And I can kill a process, given the security to do so. But the issue I am facing, is other processes which lock onto a file, and never release them. The lock remain untilt he process ends. The process has obviously forgotten about the file locks it has, and has moved forward. The process is otherwise, OK, and needs to be left alone. Albeit, like I said, if I could remove the locks, and then later on for whatever reason, the process that still thinks it has the lock, then tried to use the file/directory again, it would get an error, like Invalid File Handle.<br/><br/>Any ideas?<br/><br/>

View the full article
 
Back
Top