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

Li Wei 20 Reputation points
2023-08-07T16:31:08.74+00:00

Hello,

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?

Thank you,
Regards.

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,158 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,870 questions
Visual Studio Extensions
Visual Studio Extensions
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Extensions: A program or program module that adds functionality to or extends the effectiveness of a program.
192 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,929 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 43,046 Reputation points
    2023-08-07T21:39:42.8633333+00:00

    So, I needed a solution that forces a user to run the setup.exe with the admin rights.

    The Visual Studio Installer Project extension creates a setup.exe that is manifested to run "asInvoker". If you want to force setup.exe to run as Administrator then you need to manually change the setup.exe manifest.

    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. In my quick and dirty test that is the only consent prompt that will be seen.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. RLWA32 43,046 Reputation points
    2023-08-07T19:33:03.8766667+00:00

    Using VS2019 I created an installer for a Windows Desktop application that was configured to install the application under the C:\Program Files folder so elevated privileges as Administrator were required. The installer project was also configured to install as a prerequisite the VC++ x64 redistributable.

    I tested this installation on a Win10 VM that did not have the VC++ runtime installed on it. It didn't matter whether RequiresElevation was set to TRUE or FALSE. In every case consent prompts for Administrator privileges were received and the application was installed to a subfolder under C:\Program Files.

    What was different was the timing of when consent prompts were received when running setup.exe. When RequiresElevation was set to TRUE a consent prompt was received when installing the VC++ redistributable and again BEFORE the installation of the .msi began. If RequiresElevation was set to FALSE the second consent prompt was received after the installation of the .msi started.

    In all cases installing the .msi without running setup.exe resulted in a consent prompt.