有没有办法以编程方式安装提示权限升级(UAC)的软件?

发布于 2024-12-29 07:22:47 字数 106 浏览 3 评论 0原文

基本上我要么需要用我的程序单击UAC按钮(我认为这是不可能的),要么以某种方式做到这一点,这样我就不需要单击按钮来安装软件。我还需要在程序安装过程中单击按钮,但我知道该怎么做。我只关心UAC的事情。

Basically I either need to Click the UAC button with my program(which i don't believe is possible) or somehow make it so I don't need to click the button to install the software. I will also need to click buttons during the install with my program but I know how to do that. I am only concerned with the UAC things.

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

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

发布评论

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

评论(3

携余温的黄昏 2025-01-05 07:22:47

无论哪种方式,用户都必须单击该按钮才能授予您继续操作的权限。这就是 UAC 的全部意义所在,如果有办法解决它,那它绝对没有任何作用。

您可以提前(在安装开始时)或稍后(在安装过程中第一次实际需要权限时)请求许可,但您必须在其中一次这样做。

标准的操作过程是在您的应用程序中嵌入一个清单,表明您需要管理权限。适用的行如下所示:

<requestedExecutionLevel level="requireAdministrator" />

或者,您可以选择依赖 UAC 的“安装程序检测” “功能

属于 UAC 一部分的第一个应用程序兼容性技术称为安装程序检测。由于大多数安装程序将二进制文件写入 Program Files 目录,因此他们绝对需要管理员权限。安装程序检测旨在扫描 EXE 的名称和资源,以确定应用程序是否是安装程序。例如,如果可执行文件名称或描述包含字符串“install”或“setup”,则可执行文件将被标记为安装程序。因此,如果通过没有管理员权限的令牌启动名为 setup.exe 的应用程序(没有应用程序清单),则会触发 UAC 提升。

在安装过程中单击按钮也不是一个好主意。如果这是您正在编写的安装程序,请在执行安装程序应用程序时指定的一些“静默安装”标志中进行编码。如果您使用的是第三方安装程序,请检查文档;很可能这样的标志已经存在。这些标志的要点是,在设置过程中根本不显示交互式 UI,这意味着没有人需要费心单击任何按钮(这是很难做到正确的)。

One way or the other, the user is going to have to click that button to give you permission to proceed. That's the whole point of UAC, if there were a way to work around it, it would serve absolutely no purpose.

You can either ask for permission sooner (at the beginning of your installation) or later (at the point in the installation when the privileges are first actually required), but you have to do it one of those times.

The standard course of action is to embed a manifest in your application that indicates you require administrative privileges. The applicable line looks like this:

<requestedExecutionLevel level="requireAdministrator" />

Alternatively, you could choose to rely on UAC's "Installer Detection" functionality:

The first application compatibility technology that is part of UAC is called Installer Detection. Because most installers write binaries to the Program Files directory, they overwhelmingly need administrator privileges. Installer Detection is designed to scan the name and the resources of the EXE to determine whether an application is an installer. For example, an executable would be marked as an installer if the executable name or description contained the strings "install" or "setup". So an application named setup.exe, without an application manifest, would trigger a UAC elevation if launched by a token without administrator privileges.

Clicking buttons during your install isn't a very good idea, either. If this is an installer that you're writing, code in some "silent install" flags that you can specify when executing the installer app. If this is a third-party installer that you're using, check the documentation; chances are such flags already exist. The point of these flags is that interactive UI is not displayed at all during setup, meaning that no one has to bother clicking any buttons (which is very hard to get right).

娇妻 2025-01-05 07:22:47

您可以将程序安装在用户的主目录或任何其他无需管理员权限即可写入的目录中。

如果您正在编写安装程序包装程序,则可以在包装程序上请求 UAC,并且包装程序可以使用管理员权限启动真正的安装程序。大多数安装程序还为无人值守安装提供命令行选项,因此您可能需要检查这些选项,而不是编写按钮单击脚本。

you can install your program in the user's home directory or any other directories which is writable without administrator privilege.

if you're writing an installer wrapper, you can ask for UAC on the wrapper and the wrapper can start the real installer(s) with administrator privilege. Most installers also provides command line options for unattended installations, so you might want to check those instead of scripting button clicks.

梨涡 2025-01-05 07:22:47

您无法单击 UAC 同意对话框上的按钮。

您的其他选择取决于您真正想要实现的目标。因此,请向我们提供有关您的任务的更多详细信息:与单击应用程序中的安装程序按钮相比,可能有更好的设计选择。
为了避免 UAC,您可以安装一个将启动安装的服务。但安装服务时必须征得用户同意。

You can't click button on UAC consent dialog.

Your other options depend on what you really try to achieve. So give us more details on the your task: there could be better design choices than clicking installer buttons from an application.
To avoid UAC, you can install a service which will start the installation. But user has to consent when you install the service.

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