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.
Usage:
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. |
Attachment | Size |
---|---|
FileLocker.zip | 15.45 KB |
FileLockerSource.zip | 9.47 KB |
Works great
This works great! It prevents both read and write access.
Note that on Windows 10, it must be run As Administrator.
Great tool!!
Thanks!!
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
Thanks!
Thanks
Just what I needed, thanks Jens
Thanks!
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 great...so does my error handling now :)
David
Hi, I would like to use this
Hi,
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
Gunther
Preview comment | Homepage of Jens Scheffler
Lieben Dank für euren nützlichen Beitrag.
Ich stöbere schon länger auf eurem informativen Weblog.
Und jetzt musste mich mal ein schnellen Kommentar da lassen bzw.
mich mal bedanken.
Macht genauso weiter, freue mich schon auf die nächsten Beiträge
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:
Jens
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!
Preview comment | Homepage of Jens Scheffler
Danke schön für Ihren tollen Artikel.
Ich habe Ihren Blog schon länger im Feed abonniert.
Und gerade musste mich mal zu Wort melden bzw. mich mal bedanken.
Machen Sie genauso weiter, freue mich schon auf die nächsten Artikel