开发者

Unable to Create or Write to a file as standard user

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 applicatio开发者_StackOverflow社区n so that it will always run as administrator.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜