Unable to create or write to file as standard user

My application creates a log file when connecting or disconnecting a server. This works well by winning XP.

There is no problem while I run it as an administrator in Vista and Win 7. But if I started it as a standard user in Vista or Win7, then he will not be able to create a log file, and I know that this is for UAC.

But how can I get around this situation so that my application runs as admin. I need to add any registry entry when installing my application so that it always runs as an administrator.

+1
source share
1 answer

If you really want this, you can add a manifest , which is why your application requires a higher UAC when it starts, but more often than not what you should do.

Most likely, you are writing a path that should not be. User mode applications should only be written to the current user folders or folder C:\Users\Public, and things like logs should be 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 the file to be shared by all users, use Environment.SpecialFolder.CommonApplicationData.

+4
source

Source: https://habr.com/ru/post/1781216/


All Articles