Unable to Create or Write to a file as standard user

时间秒杀一切 提交于 2019-12-09 23:57:42

问题


My application creates a log file when it connects or disconnects a server. This works well win win XP.

There are no issues while I run it as admin in Vista and Win 7. But if I run this as a standard user in Vista or Win7 then it fails to create the log file, and I know this is for UAC.

But how can I bypass this situation so that my app will run as admin . DO I need to add any registry entry while installing my application so that it will always run as administrator.


回答1:


If you really want to, you can add a manifest that causes your application to require UAC elevation when it is launched, but more often than not that's not what you should do.

More likely, you're writing to a path you shouldn't be. User mode applications should only write to the current users folders or the C:\Users\Public folder, and things like logs should go in C:\Users\Current User Name\Application Data\Your Program Name\. To get the ApplicationData path use Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData). Or if you want to have the file shared by all users, use Environment.SpecialFolder.CommonApplicationData.



来源:https://stackoverflow.com/questions/4487517/unable-to-create-or-write-to-a-file-as-standard-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!