Search code examples
c#winformsoperating-systemsetup-project

Execute Setup with admin rights


I have a windows forms app developed in c# and have created a setup file for it. .Net Framework used is 3.0.

Now, setup should force for admin rights for installation and then proceed else not.

I found articles on creating manifest file which works fine but when program is launched after installation it again asks for admin rights which is not i want.

And this prompt should also work on Windows XP SP 1 and above OS.


Solution

  • To prompt Installer to invoke the UAC prompt to the user you can do the following:

    • Right click your Setup Project > View > Launch Conditions.
    • Right click Launch Conditions > Add a new Condition in your Launch Conditions.
    • Right click the Condition, choose Properties Window.
    • Set Condition to AdminUser. (You can also try setting Privileged property)
    • Build and install

    OR

      Edit your .vdproj, change requiresElevation attribute to true

    "MsiBootstrapper"
    {
    
        "RequiresElevation" = "11:TRUE"
    }