如何使 VS2010 安装项目中的 setup.exe 请求管理员权限?

发布于 2024-12-05 05:16:25 字数 918 浏览 2 评论 0原文

我有一个问题,我想这个问题很容易解决......但是呃。

我正在使用 VS2010 部署 .NET 应用程序。我有一个 C# Windows 窗体项目和一个部署项目。我需要安装程序以管理员权限运行,因为该应用程序是为所有用户安装的,并且已在注册表中创建一个条目。

启动 setup.exe 时,系统不会提示我进行权限提升。安装程序将启动并建议安装到 Program Files (x86),这很好。单击“下一步”后,安装程序将运行并完成并显示成功消息。这基本上是一个谎言,因为它没有成功安装。相反,它将应用程序 exe 直接放入 C:\。

如何让安装程序请求管理员权限。或者我是否必须依赖我的客户右键单击设置并选择“以管理员身份运行”,这很容易出错?

有关我的设置的说明

  • 在设置项目的文件系统视图中,我添加了(除其他外)“project01(活动)的主要输出”和“project01(活动)的构建输出”到“应用程序文件夹” ”。我还在“用户程序菜单\公司名称\程序名称”中添加了“主输出”的快捷方式。
  • 在注册表视图中,我向 HKEY_CLASSES_ROOT 添加了一个条目,因为我需要注册一个 url 我还修改了安装

程序的设置:我将 InstallAllUsers 设置为 True,因为

当我通过双击(或从项目的上下文菜单中选择安装)构建并启动 setup.exe 时,我总是得到相同的结果。结果:安装程序运行时不要求管理员权限,要求安装位置(我将其保留在默认的 C:\Program Files(x86)\Company\ProgramName),然后单击“下一步”后继续,结果是 exe。直接放在 C:\ 中,创建的快捷方式当然指向 Nirvana,

如果我以管理员身份手动运行 setup.exe,一切都会正常。但这并不是真正的出路。

那么我怎样才能让安装程序始终以管理员身份运行呢?

I have a problem which I guessed would be really simple to solve... but duh.

I'm deploying a .NET application with VS2010. I have a C# Windows Forms project and a Deployment Project. I need the installer to run with admin privileges because the app is installed for all users and an entry to the registry is made.

When starting the setup.exe I'm not prompted for privilege elevation. The installer will just start and suggest to install to Program Files (x86) which is good. After clicking next the installer runs and finished with a success message. Which is basically a lie because it did not successfully install. Instead it puts the apps exe directly to C:\.

How can I make the installer ask for admin privileges. Or do I have to rely on my customer to right click the setup and select "Run as Admin" which is very error prone?

Clarifications about my setup:

  • In the File System view of the setup project I added (among other things) "Primary Output from project01 (Active)" and "Build Outputs from project01 (Active) to "Application Folder". I also added a shortcut to "Primary Output" into "User's Programs Menu\CompanyName\ProgramName".
  • In the Registry View I added an entry to HKEY_CLASSES_ROOT because I need to register an url handler.

I also modified the setup's settings: I set InstallAllUsers to True because it is supposed to do so.

When I build and start the setup.exe by double clicking (or by selecting Install from the project's context menu) I always get the same result: The installer runs without asking for admin privileges, ask for an install location (which I leave at the default C:\Program Files(x86)\Company\ProgramName) and then procedes after clicking Next. As a result, the exe is put directly in C:\ and the shortcut created of course points into Nirvana.

If I run the setup.exe manually as Administrator things work fine. But this cannot seriously be the way to go.

So how can I tell the setup to always run as Admin?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

追星践月 2024-12-12 05:16:25

我认为这是一个完全有效的问题,是一个真正的问题,并且有一个实际的解释。

我最近遇到了这个问题。就我而言,原因是 AlwaysInstallElevated 策略是通过 GPO 在计算机上设置的。该策略在每台机器策略中设置为 1,在每用户策略中设置为 0。可以手动设置这些策略以重现它对 MSI 安装程序的影响

使用 msexec /log install.log /i Deploy.msi,我有一个安装日志,其中有如下字符串

MSI (s) (A4:8C) [13:00:42:885]: Ignoring disallowed property TARGETDIR
MSI (s) (A4:8C) [13:00:42:885]: Ignoring disallowed property VSDNETURLMSG
MSI (s) (A4:8C) [13:00:42:885]: Ignoring disallowed property VSDNETMSG

:似乎 Visual Studio 没有设置 SecureCustomProperties 在 MSI 中正确存在,并且需要某种后处理。我认为转向 WiX 可能是一个更好的长期解决方案。

MSDN 上的博客文章是我发现的,它帮助我找到了这个问题的根本原因。

I think this is a perfectly valid question, is a real problem, and has an actual explanation.

I recently ran across this problem. In my case, the cause is that the AlwaysInstallElevated policy was set on the computer through GPO. The policy was set to 1 in the per-machine policy and 0 in the per-user policy. These policies can be manually set to reproduce the effect it has on MSI installers

Using msexec /log install.log /i Deploy.msi, I had a setup log and there were strings in it like this:

MSI (s) (A4:8C) [13:00:42:885]: Ignoring disallowed property TARGETDIR
MSI (s) (A4:8C) [13:00:42:885]: Ignoring disallowed property VSDNETURLMSG
MSI (s) (A4:8C) [13:00:42:885]: Ignoring disallowed property VSDNETMSG

It seems that Visual Studio does not set the SecureCustomProperties in the MSI correctly and post processing of some sort is needed. I think that moving to WiX may be a better long term solution instead.

A blog post on MSDN is what I found that helped me find the root cause to this problem.

日裸衫吸 2024-12-12 05:16:25

我遇到了和你一样的问题,并找到了一个足够好的解决方案。所以它可能也适合你。该解决方案记录在此处:

VS2010 安装项目 - 以管理员身份运行

我将重新- 在此简要迭代解决方案。基本上,您需要手动编辑安装项目文件 (.vdproj) 并将以下属性设置为 TRUE:

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

I've come across the same issue as you, and have found a good enough solution for it. So it might work for you too. The solution is documented here:

VS2010 Setup Project - Run As Administrator

I will re-iterate the solution briefly here. Basically, you need to manually edit the setup project file (.vdproj) and the following property to TRUE:

"MsiBootstrapper"
{
    ...
    "RequiresElevation" = "11:TRUE"
}
风筝有风,海豚有海 2024-12-12 05:16:25

启动 setup.exe 时,系统不会提示我进行权限提升。

这是正常行为。助推器不需要升高。

这基本上是一个谎言,因为它没有成功安装。
相反,它将应用程序 exe 直接放入 C:。

所以它确实安装了您的应用程序,但位置错误。这与海拔无关。在安装项目的文件系统编辑器中,您在哪里添加了应用程序文件?您是否将它们添加到“应用程序文件夹”中?

如何让安装程序请求管理员权限。

单击“安装”按钮时,为所有用户安装的 MSI 包会自动提示提升。如果它没有自动提升并安装在每台计算机的位置(例如 C:),则安装将失败并且不会在目标计算机上复制任何内容。

When starting the setup.exe I'm not prompted for privilege elevation.

This is the normal behavior. The boostrapper doesn't need elevation.

Which is basically a lie because it did not successfully install.
Instead it puts the apps exe directly to C:.

So it did install your application, but in the wrong location. This is not related to elevation. In the File System editor in your setup project where did you add your application files? Did you add them in "Application Folder"?

How can I make the installer ask for admin privileges.

A MSI package installed for all users automatically prompts for elevation when clicking Install button. If it doesn't elevate automatically and installs in a per-machine location (like C:), the installation fails and nothing is copied on the target machine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文