2

How do I prevent my .net (C#) program from ever writing to disk?

Edit: There's a FileIOPermissionAttribute for anyone curious. This codeproject also shows a way.

Eugene
  • 10,957
  • 20
  • 69
  • 97
  • Technically, you can't. Someone could inject IL or a native DLL to cause writes to disk. You could use Sandboxie though. – Polynomial Nov 04 '11 at 00:16

2 Answers2

2

You can run it with an account that is not authorized to write to disk.

Toto
  • 56
  • 2
  • You can have a Windows account that's not authorized to write to disk at all? How does it write its own settings? – svick Nov 04 '11 at 01:05
2

You can use caspol to ensure that the exe is not executed with "full trust", and limit the trust excluding that permission (FileIOPermission). However, if the exe is not designed and tested to run without full trust, it could completely fail to do anything.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900