Search code examples
c#.netwinformsuac

“Save” admin privileges for deployed program


I wrote a program which uses some file reading/writing. Then deployed, and installed on my computer. The problem is that if I don’t run the program as an administrator it doesn’t “get” access to the folder/files. If I set up the program in the manifest file to the “requireAdministrator” setting, UAC always prompts me to give it the rights.

I tried to run the program without the manifest setting (set as asInvoker), and after installation, set the folder/files security settings to grant users the same rights as admins. Result: works perfectly fine.

More solutions “acceptable”:

1: I would like to “save” the admin settings, without constant uac prompt. (It would be more convenient to a user to install the program only, and not to dive into the folder settings and change the security properties.)

2: Run a script after install to set the folder settings for the users, (and manifest set asInvoker).

3: Any other idea? :-D


Solution

  • I had a similar issue with one of my projects. It's by design, could you imagine if any executable had admin level read/writes? WinXP 'fun' all over again.

    A 'lazy' workaround: I just installed it to C:\Users\(user)\(program) folder and used relative paths for everything. You could direct your installer to install your application there by default instead. As long as you don't truly need admin rights for anything else, you should be fine. I believe Visual Studio Code has a build that does that as well so it's not unheard of.

    A less lazy workaround: Use a folder within AppData or Documents folders to read/write all your data files from.

    Good luck :)