Unable to Create or Write to a file as standard us

2020-08-02 11:53发布

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条回答
We Are One
2楼-- · 2020-08-02 12:31

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.

查看更多
登录 后发表回答