windows 自动为快捷方式设置“以管理员身份运行”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3716782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:15:04  来源:igfitidea点击:

Set "Run as Administrator" for shortcut automaticlly

windowswindows-7runas

提问by TalkingCode

In Windows 7, you can set a property of a shortcut to "Run as Administrator", so that the application is invoked with Administrator privileges or the user is asked for an admin account.

在 Windows 7 中,您可以将快捷方式的属性设置为“以管理员身份运行”,以便使用管理员权限调用应用程序或要求用户提供管理员帐户。

I know I can request/force Administrator privileges with a manifest file for my application, but I need to set the privileges for applications that are not mine. As Installer Software I use SetUp Factory 8. It will create a shortcut but doesn't set "Run as Administrator".

我知道我可以使用我的应用程序的清单文件请求/强制管理员权限,但我需要为不属于我的应用程序设置权限。作为安装程序软件,我使用 SetUp Factory 8。它会创建一个快捷方式,但不会设置“以管理员身份运行”。

So far I set the option with every customer manually after install but that is a lot of work.

到目前为止,我在安装后手动为每个客户设置了该选项,但这需要大量工作。

How can I set "Run as Administrator" for application shortcuts via a program/script (like editing the shortcut) or in any other way.

如何通过程序/脚本(如编辑快捷方式)或以任何其他方式为应用程序快捷方式设置“以管理员身份运行”。

回答by Kate Gregory

You know that you can embed a manifest, but it seems like you don't know you can also have an external manifest. You don't need to compile the executable for this. Just name the file whatever.exe.manifest and put it in the same folder as whatever.exe. If that manifest says requireAdministrator, you'll request elevation on every run. Have your installer copy the manifest wherever it copies the exe.

您知道您可以嵌入一个清单,但您似乎不知道您也可以拥有一个外部清单。您不需要为此编译可执行文件。只需将文件命名为whatever.exe.manifest 并将其放在与whatever.exe 相同的文件夹中。如果该清单显示 requireAdministrator,您将在每次运行时请求提升。让您的安装程序在复制 exe 的任何位置复制清单。