FileLocker - a small tool to lock files

Did you also sometimes want to test exception cases and the right tools are missing?

I recently wanted to test a locked file exception in Java but from implementing the test it seems there is no easy way in Windows to lock a file for testing (at least I'm not aware of, hints are welcome...) - so I was writing a small command line tool to help me implementing my test cases.

The FileLocker is a Windows NT/2000/XP/2003/Vista/7 32Bit command line tool to lock a file. The lock is a read/write/delete lock. The lock will be released once you kill the program or after a specified time / keypress.


FileLocker [/T LockTime] [/I] [/K] [/Q] file [file...]
/T LockTime Time in milliseconds to lock the file
/I Infinite locking until process is killed (default)
/K Lock file until key is pressed
/Q Be quiet.


FileLocker.zip15.45 KB
FileLockerSource.zip9.47 KB

Great tool!!


Really helpful

That's such a smart utility - and just like everyone else here I've used it to track down some file locking errors in my app.


Good one!

Great tool



Just what I needed, thanks Jens


Thanks a lot, it work well!

Thank you!

Very helpful. I wanted to test Robocopy's /r and /w switches and your program (using the start command to run it in another process) helped me accomplish my goal.

Nice Work

Thanks for the tool, I was needing to test locked file handling as well.  Works does my error handling now :)



Hi, I would like to use this


I would like to use this tool in a batchscript for that:

1. set a exclusive lock on file test.log

2. copy test.log with FastCopy to another path

3. unlock the file test.log 

Is it possible to do this with your tool or is it possible to change the tool.

Thanks for your help


Hi Gunther,   I assume you

Hi Gunther,


I assume you need to make a script / batch file around the tool to get the desired results:

  1. Start FileLocker as a seperate process
  2. sleep for 1 second
  3. Start FastCopy
  4. kill the FlieLocker process to remove the lock, use "killall" for example


Exactly what I was looking for!

During development, the need arose to test a case when a local file is locked by another program.

Thanks a lot for this small tool, it simplified my work a lot!