VS2010安装项目-以管理员身份运行 [英] VS2010 Setup Project - Run As Administrator

查看:131
本文介绍了VS2010安装项目-以管理员身份运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VS2010解决方案,其中包含2个项目-.NET 4程序和该程序的安装程序.安装程序只是具有前提条件的简单安装项目-.NET Framework 4.

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.

问题是我需要安装程序 setup.exe 始终以管理员身份运行,否则安装将在UAC下失败. (默认情况下,它不会提示我特权提升.)

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.)

我尝试将 setup.exe.manifest (如下所示)放在setup.exe旁边,以强制其以管理员身份运行,但不幸的是Windows忽略了它,很可能是因为已经存在嵌入在setup.exe本身中的>另一个清单文件,它设置为 asInvoker ,而不是 requireAdministrator .

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.

那也不起作用.

那么任何人都可以阐明如何解决此问题吗?

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

P.S.我知道您可以通过更改setup.exe的兼容性设置来解决此问题,但这是一个手动过程,无法通过自动生成过程(TFS)完成.另外,提供具有兼容性设置的快捷方式也很奇怪,因为没有人在同一文件夹中提供setup.exe的快捷方式,更不用说该快捷方式需要事先知道setup.exe的确切路径. (安装包将随处移动.)

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.)

顺便说一句,我的问题与

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.

推荐答案

正如Frank指出的那样,Visual Studio安装程序项目的行为记录在Microsoft网站上:

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

Visual Studio安装程序部署

换句话说,由VS008和VS2010生成的setup.exe将始终 运行,而不会提示特权提升(除非您使用' Run As Administrator 明确运行它) >"上下文菜单选项).它依次将每个必备组件以及主MSI安装程序作为单独的进程运行,并提示需要它们的任何人提升特权.这意味着可能会有多个提示.

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.

但是,由于某些原因,这并不总是有效.就我而言,当我运行setup.exe时,根本没有出现.NET Framework必备组件的提升提示. 但是,如果我直接运行必备安装程序,将出现提示.这意味着问题不在于必备组件,而在于setup.exe或Windows本身.

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.

解决方案(或解决方法)?根据Microsoft在上面的链接中的描述,我们可以强制 setup.exe启动每个必备组件,并且主MSI可以运行带有 提升提示的主MSI.为此,我们需要手动编辑安装项目文件(.vdproj),并将以下RequiresElevation值更改为 TRUE ,如下所示:

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.

这篇关于VS2010安装项目-以管理员身份运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆