如何创建快捷方式以从 cmd 行启动具有管理员权限的应用程序? [英] How to create a shortcut to launch an App with admin privileges from the cmd-line?

查看:24
本文介绍了如何创建快捷方式以从 cmd 行启动具有管理员权限的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个安装程序 (Inno-Setup),可将我的应用程序安装到用户定义的路径.在安装程序结束时,我想创建一个快捷方式,以管理员权限启动应用程序.该解决方案应该适用于从 winXP 到 Win7 的所有 win 版本.

我能做些什么来实现这一目标?

我知道它是 可能的批处理脚本,它执行一个讨厌的 vb 脚本.缺点是 cmd-window 弹出窗口,我猜它只适用于 win7.

我还尝试了命令 mklink 来创建超链接,但它不起作用,因为无法传递设置管理员权限的参数.

I have an installer (Inno-Setup) that installs my application to a path defined by the user. At the end of the install routine i want to create a shortcut that starts the application with admin privileges. The solution should work on all win version from winXP to Win7.

What can i do to achieve this?

I know that it is possible with a batch script, that executes a nasty vb-script. The disadvantage is that the cmd-window popup and it only works on win7 i guess.

I also tried the command mklink to create a hyperlink, but it does not work because it is not possible to pass an argument that set the admin priviliges.

推荐答案

您可以添加一个注册表项,告诉 Windows 以管理员身份执行您的程序:

You can add a registry-key that tells windows to execute your program as admin:

HKCUSoftwareMicrosoftWindows NTCurrentVersionAppCompatFlagsLayers下,添加一个key(REG_SZ) 和值RUNASADMIN.当您启动 exe 时,系统会提示您进行管理员访问.

Under HKCUSoftwareMicrosoftWindows NTCurrentVersionAppCompatFlagsLayers, just add a key(REG_SZ) <Path to your exe> with the value RUNASADMIN. When you launch your exe, you will be prompted for admin-access.

这样,您就可以像使用 Inno-Setup 一样简单地为可执行文件创建一个普通的快捷方式.

With that, you can simply create a normal shortcut to your executable like you would do it with Inno-Setup.

如果您想通过 cmd 或批处理文件执行此操作,可以使用以下命令:

If you want to do so via a cmd or a batch-file, you can use the following command:

reg add "HKCUSoftwareMicrosoftWindows NTCurrentVersionAppCompatFlagsLayers" /v "<Path to your exe>" /t REG_SZ /d RUNASADMIN

这篇关于如何创建快捷方式以从 cmd 行启动具有管理员权限的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆