.:[ Please always use http://www.32bits.co.uk to access the site. Thanks! ]:.
Last updated: 10:55 AM Monday October 2008

DLock - File and Folder Locking Tool
[ Download DLock v1.0 BETA VERSION 2 here ]
![]()
...to DLock - a mildly useful tool for busy people. Created in some spare time over a while by a very busy non-professional coder. I guess it sounds better if I say it was coded in 27 minutes before a party.
![]()
Good question. Back in January 2002 there was a thread on the Vuln-Dev list about spyware and trojan files. This led into a discussion about how you can prevent trojans from creating files on your system, and finding out when they had. So, I offered to write a little tool that would lock specific files so they couldn't be accessed. Some people googled around and found there didn't seem to be a tool to do this already. That was the theory. In practice, I started coding the tool then took the opportunity to brush up my coding. So, we now have a full blown multithreaded file and folder watcher tool. DLock v1.o has 3 modes of operation, and probably many more of total failure. It can lock a file for exclusive access, it can watch your system and alert you when files and folders are created, or it can watch your system and alert you when existing files and folders have changes made to/in them. Like I said, mildly useful. So, here come the rapid docs:
This is the main DLock window.
The important bits, in order:
1. Type the names of files and folders you wish to add to the watch list in here, and click submit.
2. The watch list. This is not necessarily a list of the files which are currently being watched.
3. Use these buttons to modify the watch list entries.
4. When you click OK, DLock will parse the current watch list, and begin monitoring using your chosen method. If you have chosen a threaded method (6 or 7), and the thread is already running, your changes will be submitted to the thread.
5. Select this to use the Open File method. See the "Open File" section.
6. Select this to use the Block Process method. See the "Block Process" section.
7. Select this to use the Idle Process method. See the "Idle Process" section.
8. This is the time interval in milliseconds between checks when using the Idle Process method.
9. The info line. A bit of info about the last action/result/problem will be displayed here.
10. The status field. This tells you the current status of DLock monitor - whether it's active, suspended, quit because it found a watched file etc.
11. Click this button to immediately suspend monitoring. Monitoring won't resume until you click it again.
12. Take a guess. It immediately cleans up and quits.
13. Click this button to send a "ping" to the thread (only when in Block or Idle Process methods). The background thread will reply to tell you it's still there and working. Beats using process viewer, eh.
14. Click this button to get the background thread to quit (again, only in Block or Idle methods).
The methods in a bit more detail:
Open File
This is the simplest method, and was the original purpose. DLock will go through the watch list and open an exclusive lock on the files you specify. If it can't open a file for any reason, it'll tell you. Note that to make this lock work, DLock opens the files with MODE_CREATE. This means that if you specify files that don't already exist on your hd, DLock has to create them. They will appear as 0 byte files, and will be unaccessible whilst DLock locking is active.
- Type a filename, eg: c:\dlocktest.txt in the filename field (numbered 1 above)
- Click Submit
- Click "Open File" in the Options box
- Click OK
- Read the warning and accept itLocking is now working. If you browse to c:\ and try to open/delete/move dlocktest.txt, you'll be denied access. Go back to DLock, and click "Suspend". Return to the browser window. You can now delete/move/open dlocktest.txt.
Blocked Process
The most complicated method. DLock will launch a background thread, and tell Windows to notify it when any change is made to any of the files or folders (folder contents, including subfolders). Changes include attribute changes, size changes, renames, deletes, permissions etc. There is a limitation to this method. The win32api only allows for folders to be watched in this way, so strictly DLock only submits folder names to the blocked process. However, if you put a filename in the watch list, then select this monitor method, DLock will strip the folder name out and use that for monitoring. If a signal is raised against that folder, DLock will match the folder to the full pathname and inform you about that. There are a few problems with this. Firstly, if you submit 2 files in the same directory to this method, DLock will always show the first file as the one that signalled. Secondly, because of the 1st reason, if you submit a filename to DLock and also submit the directory name, DLock will never signal on the filename. Eg, if you submit c:\test\1.txt and c:\test to the watch list, and the blocked process signals for c:\test\1.txt, it will still report a change in the the c:\test folder only. Sorry, but thats life.
- Type a directory name, eg: c:\winnt in the filename field (numbered 1 above)
- Click Submit
- Click "Block Process"
- Click OK
- Read the warning and accept itWatching is now working. If a change occurs inside c:\winnt, DLock will immediately alert you to it. That will probably take all of 1 second. Go back to DLock and click "Exit Thread", and monitoring is finished. Note that if blocked process watching is signalled and finds a change, it immediately notifies you and exits. Therefore you will need to click OK to re-submit the watch list and restart monitoring. Clicking "Exit Thread" when the blocked thread is running will cause it to immediately exit (and end the monitoring). Clicking "Suspend" will suspend monitoring until you resume it. DLock consumes no CPU time when suspended.
Idle Process
Idle processing is a cpu efficient way of watching for creation of a filer or folder. DLock will launch a thread running at idle priority which at intervals will check if any of the files in the watch list have been created. Note the slider/text box that appears when you select this method. You are able to set the interval in milliseconds between idle processing checks. The increments are in 50ms steps, with 50ms being pretty much the quickest interval Windows can manage (excluding multimedia timers). Because the thread sleeps on the system timer, if your system is extremely busy the actual check interval may not exactly match the interval you specify.
- Type a filename that does not exist, eg: c:\dlocktest.txt
- Click Submit
- Click "Idle Process"
- Set a check interval of approx 500ms
- Click OK
- Read the warning and accept itIdle watching is now working. DLock consumes no cpu time when waiting in idle processing mode. If you now create the file you set DLock to monitor (ie c:\dlocktest.txt), when the check interval timer elapses DLock will find the file and notify you. Clicking "Ping Thread" will send a request to the background thread to check it's still alive and working. DLock will notify you whether or not the thread responded, and will advise you what to do if it didn't. Clicking "Exit Thread" when the blocked thread is running will cause it to immediately exit (and end the monitoring). Clicking "Suspend" will suspend monitoring until you resume it. DLock consumes no CPU time when suspended.
Some other random facts:
- DLock minimizes to the system tray. Thats nice. Double click the padlock icon to pop it back on screen.
- If DLock monitoring finds a file/change while minimized, it will auto-pop back and harass you about it.
- DLock saves it's data file in it's working directory. This is just a plaintext file with the contents of the watch window.
- DLock is nice and doesn't fiddle with the registry. Therefore to uninstall it, just make use of the delete key.
- DLock is really CPU efficient. Threads are blocked and idle-ized, so on an Athlon 1gig 384meg Win2k it uses 0% CPU average.
- You might like to put DLock in your startup folder. You might also like to put it in your recycle bin. It's your choice.
- DLock is emailware. So, whether it goes in the recycler or startup, send an email to tell us why.Known problems/bugs:
- On occasion the background thread and main app get out of synch. You'll probably need to restart DLock to fix it.
- DLock does try to recover lost threads. It's pretty good with the cleanup, but lots of stopping and starting threads might cause trouble.
- DLock really should remove the locking files for "Lock Files" method, but it doesn't. Maybe v1.1...
- I was going to implement OLE drag-n-drop for files & folders, but I'm too busy/lazy. Maybe v1.1 too...
- DLock likes a PC in a sunny location with plenty of light and water. Keep it fed and watered, and it will be your companion for life.
Thats about all, folks. If it trashes your hd, neuters your cat or runs off with your wife, 32Bits.co.uk is not responsible. We're *really* not responsible if you do something stupid with it, like open-file locking pagefile.sys or something. Mail us and say why you like it, why you hate it, what you want changed or added, if you want to see any other tools from 32Bits.co.uk, or if you think we should just give up coding.