我怎么能自动提升我的批处理文件,这样它的UAC管理员权限,如果需要的话要求? [英] How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?

查看:623
本文介绍了我怎么能自动提升我的批处理文件,这样它的UAC管理员权限,如果需要的话要求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想只运行升高我的批处理文件。如果没有升高,为用户提供到升高的重新启动批次的选项。

I want my batch file to only run elevated. If not elevated, provide an option for the user to relaunch batch as elevated.

我在写一个批处理文件来设置一个系统变量,两个文件复制到的程序文件的位置,并启动驱动程序安装程序。如果Windows  7 / Windows和NBSP; Vista的用户( UAC 的启用,即使他们是本地管理员)运行时,它不正确-clicking并选择以管理员身份运行,他们将获得拒绝访问复制这两个文件,​​并写入系统变量。

I'm writing a batch file to set a system variable, copy two files to a Program Files location, and start a driver installer. If a Windows 7/Windows Vista user (UAC enabled and even if they are a local admin) runs it without right-clicking and selecting "Run as Administrator", they will get 'Access Denied' copying the two files and writing the system variable.

我想用的命令,如果用户实际上是一个管理员升高的自动重启批次。否则,如果他们不是管理员,我想告诉他们,他们需要管理员权限才能运行该批处理文件。我使用的 XCOPY 复制文件和 REG ADD 写的系统变量。我使用这些命令,以应对可能出现的Windows  XP的机器。我发现关于这个主题类似的问题,但没有与重振一个批处理文件升高交易。

I would like to use a command to automatically restart the batch as elevated if the user is in fact an administrator. Otherwise, if they are not an administrator, I want to tell them that they need administrator privileges to run the batch file. I'm using xcopy to copy the files and REG ADD to write the system variable. I'm using those commands to deal with possible Windows XP machines. I've found similar questions on this topic, but nothing that deals with relaunching a batch file as elevated.

推荐答案

您可以有脚本调用本身 PSEXEC -h 选项来运行升高。

You can have the script call itself with psexec's -h option to run elevated.

我不知道,如果它已经运行,为提升或你将如何检测不...也许升高烫发重新尝试仅如果有一个拒绝访问错误?

I'm not sure how you would detect if it's already running as elevated or not... maybe re-try with elevated perms only if there's an Access Denied error?

或者,你可以简单地对在 XCOPY REG.EXE 始终与<$运行命令C $ C> PSEXEC -h ,但如果(如果你在脚本中包含的密码或不安全的),他们需要每次输入密码这将是恼人的最终用户...

Or, you could simply have the commands for the xcopy and reg.exe always be run with psexec -h, but it would be annoying for the end-user if they need to input their password each time (or insecure if you included the password in the script)...

这篇关于我怎么能自动提升我的批处理文件,这样它的UAC管理员权限,如果需要的话要求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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