I need a way to trick another program into thinking a file is already in use using C#.
Asked
Active
Viewed 114 times
-1
-
7Trick it? Why not just open the file? – Collin May 19 '13 at 23:45
-
Will that work? I need the other program to see that the file is in use so that it opens it in read only mode. – Jake Tigchelaar May 19 '13 at 23:48
-
Opening it would make it "in use"... – Collin May 19 '13 at 23:49
-
so simply using File.Open(path, FileMode.Open) should do the trick? Ill give it a try. Thanks! – Jake Tigchelaar May 19 '13 at 23:53
-
1http://stackoverflow.com/questions/4964588/open-file-readonly – Cyral May 19 '13 at 23:57
-
So once i have it open how do i close it? I am trying to "lock" file s so that someone who should only be viewing doesn't accidently change anything – Jake Tigchelaar May 20 '13 at 00:03
-
I've removed unrelated "searched for XXX"/"thank you notes". Please try next time to show code you have problem with. On closing files it may be good idea to simply look at samples in MSDN - and than ask questions if you have problems with code there. – Alexei Levenkov May 20 '13 at 01:31
-
See @Cyral's comment, instead of opening a file so you can open it in read only mode in another application, why not open it in read only mode? – whastupduck May 20 '13 at 01:53
1 Answers
1
If you want to 'trick' the system you should just open the file in the C# code.
This will result in a 'Process cannot access file because another process is currently using the file' type message.
In C# just use the File.Open() method and avoid calling the Close() method.
Rob Aston
- 818
- 13
- 19
-
it throws an error saying its missing "Desktop.ini" from my din/debug folder? – Jake Tigchelaar May 20 '13 at 00:11
-
I'm not sure this is caused by using the open method. If you have any other projects or code in the solution that would require this file then you may need to place it there yourself. – Rob Aston May 20 '13 at 00:31