0

I perform some read/write operations on files in my app. It's still under development so for easiness I keep files locally.

In the beginning I want to check if app is started from protected directory (such as c:/Program Files) to avoid getting crash caused by lack of admin privileges. Is there any simple way to do it in C#?

I check some solutions, posted here, connected with checking read/write permissions but they don't work in my case.

0xddr
  • 65
  • 1
  • 8

1 Answers1

1

Why not just catch the exception when you attempt to read/write from the directory and handle it gracefully? You're going to need to wrap your read/writes in a try/catch anyways, so why not just let that try/catch handle this situation as well as other possible I/O situations?

myermian
  • 31,823
  • 24
  • 123
  • 215
  • That might works, but in my case problem is global (app-level, not file-level). Without possibility to read and write files app is useless, so I want prevent it to start. I'm looking for some kind of hotfix, not target solution (which is using %appdata in this case). – 0xddr Mar 22 '12 at 16:08
  • Well just consider this... once you verify that the directory is not right protected what is going to stop it from changing while your app is running? – myermian Mar 22 '12 at 16:16
  • I considered it - I don't care about this case. I just want to know if folder is protected (to be more specific system-protected) at the moment. I can simply check if app is inside Program Files, but I want to have more general solution and nothing more. – 0xddr Mar 27 '12 at 06:51