windows-installervisual-studio-2019windows-11admin-rightsvs-installer-project

Run the MSI installer built by VS installer project with admin rights


I am building an MSI installer using VS2019 and installer project extension.

The MSI must run with admin rights, so I followed the below steps.

The installer project file (*.vdproj) has the following options and if I set RequiresElevation to “TRUE”, the installer asks admin rights before proceeding the installation.

...

"MsiBootstrapper"
{
"LangId" = "3:1033"
"RequiresElevation" = "11:TRUE"
}

...

This works well for an MSI installer that has no prerequisites.

But my installer has the prerequisite (vcredist), and in this case, the above solution does not work. That is, if an installer has the prerequisites, even though I set RequiresElevation to “TRUE”, the installer does not ask admin rights before proceeding the installation.

Could you help me how to hanldle this situation?


Solution

  • The Visual Studio Installer Project extension creates a setup.exe that is manifested to run "asInvoker". Open a Developer command prompt and navigate to the location of the setup.exe file

    Extract the manifest by running the command: mt -inputresource:setup.exe;#1 -out:setup.manifest

    Edit setup.manifest to change "asInvoker" to "requireAdministrator".

    Update the manifest in setup.exe by running the command: mt -manifest setup.manifest -outputresource:setup.exe;#1

    Now running setup.exe should cause a consent prompt to be issued and thereafter it will run with elevated privileges as Administrator.