That's a feature of the OS so to actually lock out access from other processes you need to talk to the OS with it's API. You could read your file into memory and work with that before spitting out the results.
Just curious but did this come up because of over zealous Antivirus scans?