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

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

问题描述

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



我能做什么来实现这个?



我知道这是可能使用批处理脚本,执行讨厌的vb脚本。缺点是cmd窗口弹出和它只工作在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:

HKCU\Software \ Microsoft \Windows NT\CurrentVersion\AppCompatFlags\Layers 只需添加值 RUNASADMIN 的键(REG_SZ)<到您的exe的路径> 。当您启动您的exe时,系统会提示您输入管理员权限。

Under HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers, 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 "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "<Path to your exe>" /t REG_SZ /d RUNASADMIN

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

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