I have a very old application that now needs to be friendly to Windows Server 2008. It is a user application that works as singleton. It uses HKLM part of registry to read and write the configuration, and it creates log files.
Main question: how to make application work with UAC in regards to best current practice?
My initial approach is to run application non-elevated, and if configuration needs to be changed the user manually restarts it elevated, reconfigure, and restarts to non-elevated. The problem is that log file then can be created elevated as well, and then non-elevated application can not write to it. Possible workarounds:
- Don't do anything in elevated mode that implies writing to log file. But how to detect if application is in elevated mode?
- Create log file with non-elevated privileges even in elevated mode. How?
- If access is denied when opening existing log file then try to create another log file.
- Run elevated all the time.
First option is best looking so far, but how to detect the elevation? Maybe there is some other option? Maybe there is some completely different approach? I'd like not to have to change the code too much if possible.