批处理文件:删除提升的特权(以原始用户身份运行命令) [英] Batch file: Drop elevated privileges (run a command as original user)
问题描述
我有一个以特权提升(我的安装程序会生成它)开头的批处理文件,但是在某个时候,我需要以启动安装程序的原始用户身份运行命令(即从提升特权中删除).
有可能这样做吗?
您可以使用以下命令运行具有受限特权的命令:
runas /trustlevel:0x20000 "YourCommandHere"
您应该提供命令的绝对路径,包括双引号中的所有参数作为runas
的参数.
如果您要使用受限特权运行多个命令,可以将它们放在单独的批处理文件中,并使用以下命令运行:
runas /trustlevel:0x20000 "cmd /C PathToYourBatchFile"
无论如何,这将打开一个具有受限特权的新控制台.每当您希望以受限特权运行内部命令(如copy
,del
等)时,也必须使用此语法,因为这些命令由命令行解释器提供,并且没有关联的路径.>
请注意,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屋!