What are the API calls to copy a file that is currently locked. I'm hoping to be able to use .Net, but Win32 calls would be fine as well.
Please feel free to chime in about the same functionality on Unix, or any other OS.
You can copy a locked file from a disk image or hard drive by using the file system browser in OSForensics. In the file system browser choose "Add device to case" from the File menu and select the drive letter or image file you wish to copy from.
No you can't. Some programs won't lock the file for reading, but if they do, you can't get to the file without killing the other program.
In the Resource Monitor window, go to the CPU tab and expand the Associated Handles option. Now, in the search box, type the name of the file that is showing locked by a process and press Enter button. It will show you a list of processes holding the target file.
You can use the VSS (Volume Shadow Copy Service, not Visual SourceSafe) API for this purpose. While powerful, this isn't exactly an easy-to-use API: the Overview of Processing a Backup Under VSS should give you an idea what's involved.
Even though it's a relatively recent API, .NET support for VSS is pretty much (and inexcusably) nonexistent. You can't call most of the API through Interop, and the Framework file functions won't work with the kernel namespace VSS uses to expose the snapshotted files. As a bonus, there are horrendous 32/64-bit and XP-vs-Vista issues, making deployment exciting as well (the responsible team at Microsoft should be really proud!)
Anyway, the AlphaVSS project intends to bring full VSS functionality to .NET, and looks extremely promising, even though it's still in pre-beta stage. It might just do the trick for you, though, and it's open source (Managed C++).
For a good example of how to do things using Win32, see HoboCopy. The utility is quite useful on its own, and full C++ source is available from the SourceForge project page as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With