简体   繁体   English

如何使安装文件(由 IExpress 制成)在另一台计算机上以管理员身份运行

[英]How to make an install file (made from IExpress) run as administrator on another computer

I made a custom install program for a product our company develops.我为我们公司开发的产品制作了一个自定义安装程序。 Because we deal with customers that don't understand zip files, I've created an IExpress executable that unzips everything and launches the setup.exe因为我们与不理解 zip 文件的客户打交道,所以我创建了一个 IExpress 可执行文件来解压缩所有内容并启动 setup.exe

The problem I'm facing is that my setup program needs admin credentials (checking registry to see if keys exist, executing a batch script, etc).我面临的问题是我的安装程序需要管理员凭据(检查注册表以查看密钥是否存在,执行批处理脚本等)。 Up until now I've always informed customers to right-click and select "Run as Administrator".到目前为止,我一直通知客户右键单击并选择“以管理员身份运行”。 Is there a way to do this automatically, so I don't have to instruct them to right-click?有没有办法自动执行此操作,因此我不必指示他们右键单击? Customers don't like following instructions.客户不喜欢遵循说明。

Thanks in advance!提前致谢!

In the app.manifest of any C# solution there is a requestedExecutionLevel key.在任何 C# 解决方案的 app.manifest 中有一个requestedExecutionLevel键。 Changing the value of this key to requireAdministrator will always run that application as an administrator.将此键的值更改为requireAdministrator将始终以管理员身份运行该应用程序。 However, this means if a user that doesn't have admin access can't run that application.但是,这意味着如果没有管理员访问权限的用户无法运行该应用程序。 Alternatively you can set it to highestAvailable which will run for all users but if the user has admin rights then it will run as admin.或者,您可以将其设置为highestAvailable ,这将为所有用户运行,但如果用户具有管理员权限,则它将以管理员身份运行。 Hope this helps!希望这可以帮助!

I will simply expand on what rmn36 has said.我将简单地扩展 rmn36 所说的内容。 To make an IExpress generated self-extracting CAB package request for admin privileges immediately on execution, use Visual Studio (Community version 2019 works) to edit the manifest of the executable.要使 IExpress 生成的自解压 CAB 包请求在执行时立即获得管理员权限,请使用 Visual Studio(社区版 2019 有效)编辑可执行文件的清单。

From Visual Studio: File->Open your executable.从 Visual Studio:文件->打开您的可执行文件。 Open (click the + sign to the left of) the manifest (Windows 10 IExpress labels this RT_MANIFEST).打开(单击左侧的 + 号)清单(Windows 10 IExpress 标记此 RT_MANIFEST)。 There should be a '1' underneath RT_MANIFEST, double-click on it to bring up the editor. RT_MANIFEST 下应该有一个“1”,双击它以打开编辑器。 Place your cursor in the right-hand column with the text to edit normally instead of in hex.将光标放在右侧列中,以正常编辑文本而不是十六进制。 You can insert, delete, etc. even though you see binary;即使看到二进制,也可以插入、删除等; it is not fixed length.它不是固定长度。

Locate the requestedExecutionLevel key and set the level property as shown (by default it is set to "asInvoker"):找到 requestsExecutionLevel 键并设置 level 属性,如图所示(默认设置为“asInvoker”):

 <requestedExecutionLevel
          level="requireAdministrator"

Save the executable and now users no longer need to right-click and "Run as Administrator" - Windows automatically prompts.保存可执行文件,现在用户不再需要右键单击并“以管理员身份运行” - Windows 会自动提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM