11

I have a VS2010 solution with 2 projects in it - a .NET 4 program, and an installer for it. The Installer is just a simple Setup Project with a prerequisite - .NET Framework 4.

The problem is that I need the installer setup.exe to always run as Administrator otherwise the setup will fail under the UAC. (It does not prompt me for privilege elevation by default.)

I tried putting a setup.exe.manifest (shown below) alongside the setup.exe to force it to run as administrator, but unfortunately Windows ignores it, most likely because there is already another manifest file embedded within the setup.exe itself and it's set to asInvoker rather than requireAdministrator.

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>

I also tried adding a launch condition with the following properties:-

(name): Elevated
Condition: Privileged
Message: This installation requires elevated permissions to continue.

That doesn't do a thing either.

So can anyone please shed a light on how to solve this issue?

P.S. I know you can workaround this issue by changing the compatibility settings of the setup.exe, but this is a manual process and cannot be done via an automated build process (TFS). Also, providing a shortcut with compatibility setting is also weird, since no one provide a shortcut to a setup.exe in the same folder, not to mention that the shortcut needs to know the exact path of the setup.exe beforehand. (The setup package will be moved around.)


Edit: By the way, my problem is exactly the same as the one described here. But unfortunately, no solutions were found for that guy and the asker just resort to ask his clients to use Run As Administrator manually, which is what I'm trying to avoid.

Community
  • 1
  • 1
SF Lee
  • 1,647
  • 3
  • 17
  • 30

3 Answers3

16

As pointed out by Frank, the Visual Studio setup project's behavior is documented at Microsoft's web site:

Visual Studio Installer Deployment

In other words, the setup.exe produced by VS008 and VS2010 will always be run without prompting for privilege elevation (unless you explicitly run it using the 'Run As Administrator' context menu option). It in turns will run each prerequisite component as well as the main MSI installer as separate processes and prompts for privilege elevation for any of them that needs it. This means that there may be multiple prompts for elevations.

However, for some reasons this does not always work. In my case, the elevation prompt for the .NET Framework prerequisite does not come up at all when I run setup.exe. But if I run the prerequisite installer directly, the prompt will come up. This means that the problem lies not with the prerequisite component, but with either setup.exe or with Windows itself.

The solution (or workaround)? According to Microsoft in the link above, we can force setup.exe to launch each prerequisite component and the main MSI to run with elevation prompts. To do this, we need to manually edit the setup project file (.vdproj) and change the following RequiresElevation value to TRUE, as shown below:

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

This is not the ideal solution, but it is close enough to my original requirement, so I'm satisfied with this solution.

SF Lee
  • 1,647
  • 3
  • 17
  • 30
  • after opening .vdproj file where exactly do i have to set this property?? – jammy Dec 02 '14 at 06:11
  • No problem i found it ,it's right click and openwith notpad . – jammy Dec 02 '14 at 08:49
  • I had one bug with Windows 7, 64-bit, russian version where installation path of merge module was incorrect. Same installation works fine if setup.exe were launched with administrator privileges. I've tried to change setup behavior to request elevated priviledges right away - using "RequiresElevation" alterting, but unfortunately for me this solution did not work. (So elevation was requested immediately, but it did not help me with my problem) – TarmoPikaro Sep 14 '16 at 11:29
5

If you want to Run MSI in admin mode here is the way, 1) Open your Setup Project, View->Launch Conditions.

2) Right click on Launch Conditions, and add a new Condition in your Launch Conditions.

3) Right click the Condition, choose Properties Window.

4) Set Condition to

AdminUser

. 5) Build and install.

Shrivallabh
  • 2,744
  • 2
  • 25
  • 46
  • This worked for me. Looks like we can also use `Privileged` - _"installer only sets the AdminUser property if the user is an administrator. The installer sets the Privileged property if the user is an administrator, or if policy enables the user to install with elevated privileges"_ [ https://docs.microsoft.com/en-us/windows/win32/msi/adminuser ] – Noble Mar 19 '20 at 15:08
0

I think that your problem is to do with the name of the installer. This link

How do I avoid UAC when my EXE file name contains the word "update"?

says that if the name has Update or Setup in it, then UAC will kick in.

Can you rename your installer to something else?

Community
  • 1
  • 1
DeanOC
  • 6,782
  • 6
  • 40
  • 52
  • 1
    But that's what I want! I WANT the UAC to kick in, but it doesn't. Also, the name 'setup.exe' is auto-generated by Visual Studio, it cannot be changed. – SF Lee Jul 16 '12 at 01:41
  • 2
    Potentially useful background: [How UAC Works](http://msdn.microsoft.com/en-us/library/aa905330.aspx#wvduac_topic3) and [Visual Studio Installer Deployment](http://msdn.microsoft.com/en-us/library/2kt85ked.aspx) - especially the Application Elevation section – Frank Boyne Jul 16 '12 at 04:35
  • Thanks Frank, your second link actually provide the information I need! If you can provide a proper answer based on that (the part that talks about MsiBootstrapper -> RequiresElevation = True), I will accept your answer. :) – SF Lee Jul 17 '12 at 11:43