如何使用 INNO Setup 创建要求提升权限的 CMD.EXE 快捷方式?
使用 INNO Setup 我目前在 [图标] 部分下有以下条目:
Name: "{group}\My App\My App - Command Prompt"; Filename: "cmd.exe"; WorkingDir: "{app}"
此快捷方式将命令提示符直接启动到我的应用程序文件夹中。不幸的是,它没有以提升的方式启动,这意味着用户从那里运行的命令没有适当的权限。
使用 INNO Setup,如何创建需要提升的 CMD.exe(在特定文件夹中)的快捷方式?
可以通过清单文件为其他应用程序执行此操作。我的问题是,我如何使用 INNO 使用它,如果不能,我的替代方案是什么?
using INNO Setup I currently have the following entry under the [ICONS] section:
Name: "{group}\My App\My App - Command Prompt"; Filename: "cmd.exe"; WorkingDir: "{app}"
This shortcut launches a command prompt straight into my application's folder. Unfortunately it isn't launched as elevated which means the commands the user runs from there doesn't have appropriate rights.
Using INNO Setup, how can I create a shortcut to CMD.exe (in a specific folder) that requires elevation?
Doing this for other applications can be done via a manifest file. My question is, how do I use it using INNO, and if I can't, what are my alternatives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快捷方式的管理属性是兼容性设置,您不应该以编程方式设置它。用户运行的命令应该通过正确的清单来请求管理权限。用户还可以通过右键单击快捷方式并选择以管理员身份运行来选择提升自身权限。
如果您总是想立即升级,您可以在标有管理清单的应用程序文件夹中放置一个小实用程序。该实用程序要做的就是生成 cmd.exe。这样您就可以避免弄乱兼容性设置。
如果仍想使用兼容性设置,请查看 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers 和 HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers 注册表项。您还可以使用 Inno Setup 的内置 IUnknown 支持,但这需要更多工作。请参阅 CodeAutomation2.iss 示例脚本和 http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/thread/a55aa70e-ae4d-4bf6-b179-2e3df3668989
The administrative property of a shortcut is a compatibility setting, you're not supposed to set it programmatically. The commands the user runs should ask for administrative privileges themselves by having the proper manifest. The user can also choose to elevate themselves by right clicking on the shortcut and choosing Run As Administrator.
If you always want to elevate immediately anyway, you could place a little utility in your application folder marked with an administrative manifest. All this utility would do is spawn cmd.exe. That way you can avoid messing with compatibility settings.
If you still want to use the compatibility settings, take a look at the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers and HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers registry keys. You can also use Inno Setup's built in IUnknown support, but this is more work. See the CodeAutomation2.iss example script and http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/thread/a55aa70e-ae4d-4bf6-b179-2e3df3668989