开发者

UnauthorizedAccessException when writing text file to C:\ on Windows 7

I have recently moved to Windows 7. Now my .NET application fails writing log file to C:\

My TraceListener is throwing the excepti开发者_高级运维on.

A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

What to do? I am running application from the studio and so I think it must inherit all my rights and I am the admin on my pc.


If you have UAC enabled you won't be able to write files to C:\, even if you're admin, unless you start the program in elevated mode to activate the admin privileges.

Files shouldn't really be placed in the root of C:, so the best is to create a subdirectory and give yourself access rights (to your account, not the administrators group). If you really want to have the file on C:\ and not run it as elevated, you can use Windows Explorer to grant yourself (your account, not the administrators group) write access to C:\.


Your program will need to run with the required permissions. Only those with Administrator access can write to 'special' folders such as the system drive and so the application will need to execute initially with elevated privileges.

See here, and here for information on security permissions in code.


You probably have UAC still turned on.

You will need to indicate in your app.config, that you want the process to use elevated rights.

The default generated app.config have that info.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜