Search code examples
wpfmanifestuactrust

UAC and log files management


I'm writing a WPF .NET application (fwk 4.0) which references log4Net and must be installed in the 'Program Files(x86)' directory on a Windows 7/8/10 64bits OS.

The application logs created by the application are .txt files created in the installation sub-directory of the 'Program Files(x86)'

This application also uses on the SQL Server CE 4.0 in the same subdirectory.

C:\Program Files(x86)\MYAPP\APP1\APP1.txt

C:\Program Files(x86)\MYAPP\APP1\CEDatabase.sdf

The application is installed by a local administrator.

To start the application, a standard user is prompted by UAC to start with an elevated acess token (admin privileges) to run the application because it won't start otherwise (I think ACL not granted to create and write logs).

The WPF application build holds no application manifest.

My client is frustrated by the fact that a standard user can not start the application without the UAC elevation. Moreover, it wants to keep on installing in the 'Program Files (x86)'.

What can I do to manage this situation?


Solution

  • I'd strongly suggest not writing the log files to the same location as you install your application, but instead to one of the standard public locations, which you can access by environment variables.

    See this link for more details on how to set this in Log4Net : How to specify common application data folder for log4net?

    The two common locations to log to which avoid UAC restrictions are: CommonApplicationData (https://msdn.microsoft.com/en-us/library/windows/desktop/aa367992(v=vs.85).aspx) which is a location where all users can write to, so you might want to use this if you want a common logging location regardless of who is logged on to Windows and running your application.

    LocalAppData (https://msdn.microsoft.com/en-us/library/windows/desktop/aa369768(v=vs.85).aspx) which is a location specified to your currently logged on user. This would allow you to keep your log files from different Windows users separate from each other.

    I'm not sure off the top of my head whether you'd have the same issue with writes to the SQL Server CE database. The pattern I've followed in the past to work with UAC is to install all static files under Program Files, then all data under one of the above 2 mentioned folders depending on whether the application data and logging was per-user or per-installation.