2

I see that this question has been asked many times in stackoverflow, as well as in other places. The questioners solved their problem by different methods. Most of these solutions are around how they designed their applications and locking level on the files.

I understand that Windows provides Read/Write protection in different ways. But, still, if the file is on my disk, and being an administrator, can't I read the contents of the locked file forcefully? Any pointers on how I can achieve that would be greatly helpful.

The file in question is totally inaccessible to other processes through C# .NET APIs. Looks like its readlocked.

Thanks.

mutelogan
  • 6,477
  • 6
  • 20
  • 15
  • If you want help you will need to clarify your question and post the code involved in reading the file. – Security Hound Sep 23 '11 at 13:32
  • [this post](http://stackoverflow.com/questions/242882/how-can-i-unlock-a-file-that-is-locked-by-a-process-in-net) (and especially the article in the answer!) seem to be exactly about what you want (except for the deleting bit), have a read. – mtijn Sep 23 '11 at 13:37
  • Maybe more people would help if you accepted some of your answers... – Bali C Sep 23 '11 at 13:46
  • I am sorry that I couldn't give enough details. The file is locked by an application that I don't fully understand. It writes some information to a temporary file. It gets deleted the moment I close the application. I don't know what kind of lock the application uses on this file. As the temporary file grows in size continuously, I wanted to monitor the file contents. However, I couldn't open the file by .NET C# API so far. – mutelogan Sep 24 '11 at 05:09

1 Answers1

0

If file is locked from your app, you have to close all buffers/streams or whatever you have opened before.

If file is locked from something else the only solution I know is to use Unlocker, which can be run even without GUI using some console param (so using Process class in C#).
But be careful to walk this way, because you could corrupt file and create some memory leak closing with brute force opened handles and probably application that was using them.

Marco
  • 56,740
  • 14
  • 129
  • 152