I'm using DeviceIoControl with FSCTL_LOCK_VOLUME to lock a USB pen drive prior to direct disk read/write. The program works - sometimes. I am having an issue with the lock call itself. When I step the command in Visual Studio 2008 the result is correct and the lock succeeds - every time!, when running the code (debug or not) the call fails sporadically with invalid handle. The only noticable difference is when stepping there is a half second pause - which I am happy with, but when running/debugging the call fails immediately.
Please can you give me a hint as to where this is falling down.
I think this is one for the true techies!