批处理文件:删除提升的特权(以原始用户身份运行命令) [英] Batch file: Drop elevated privileges (run a command as original user)

查看:84
本文介绍了批处理文件:删除提升的特权(以原始用户身份运行命令)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以特权提升(我的安装程序会生成它)开头的批处理文件,但是在某个时候,我需要以启动安装程序的原始用户身份运行命令(即从提升特权中删除).

有可能这样做吗?

解决方案

您可以使用以下命令运行具有受限特权的命令:

runas /trustlevel:0x20000 "YourCommandHere"

您应该提供命令的绝对路径,包括双引号中的所有参数作为runas的参数.

如果您要使用受限特权运行多个命令,可以将它们放在单独的批处理文件中,并使用以下命令运行:

runas /trustlevel:0x20000 "cmd /C PathToYourBatchFile"

无论如何,这将打开一个具有受限特权的新控制台.每当您希望以受限特权运行内部命令(如copydel等)时,也必须使用此语法,因为这些命令由命令行解释器提供,并且没有关联的路径.

请注意,0x20000是标准用户的信任级别.您可以通过运行

列出其他可用的信任级别

runas /showtrustlevels

I have a batch file that starts with elevated privileges (my installer spawns it), but at a certain point I need to run a command as the original user who started my installer (i.e. drop from the elevated privileges).

Is it possible to do so?

解决方案

You can run a command with restricted privileges with:

runas /trustlevel:0x20000 "YourCommandHere"

You should provide the absolute path to your command including any arguments in double quotes as an argument to runas.

If you would like to run more than one command with restricted privileges, you can put them in a separate batch file and run it with:

runas /trustlevel:0x20000 "cmd /C PathToYourBatchFile"

Anyway, this will open a new console with restricted privileges. You also have to use this syntax whenever you wish to run with restricted privileges an internal command (like copy, del, etc.) as these are provided by the command line interpreter and do not have an associated path.

Note that 0x20000 is the trust level of standard users. You can list other available trust levels by running

runas /showtrustlevels

这篇关于批处理文件:删除提升的特权(以原始用户身份运行命令)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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