是否使用提升的权限从批处理文件运行Powershell脚本?
我想从是否使用提升的权限从批处理文件运行Powershell脚本?,powershell,batch-file,Powershell,Batch File,我想从code.bat 我知道start命令将运行它,但要求它以管理员身份运行,我如何才能做到这一点?在批处理文件中: powershell -Command "&{ Start-Process powershell -ArgumentList '-File C:\folder\psfile.ps1' -Verb RunAs}" …基本上,您正在使用Powershell运行Powershell。第二个实例被提升为Admin,正在使用这些权限运行脚本 详细说明: Start Proce
code.bat
我知道start
命令将运行它,但要求它以管理员身份运行,我如何才能做到这一点?在批处理文件中:
powershell -Command "&{ Start-Process powershell -ArgumentList '-File C:\folder\psfile.ps1' -Verb RunAs}"
…基本上,您正在使用Powershell运行Powershell。第二个实例被提升为Admin,正在使用这些权限运行脚本
详细说明:
Start Process
可用于运行程序,并且还具有参数-Verb RunAs
,该参数将程序提升为以管理员身份运行
我们不能从批处理文件调用启动进程
,因为它是PowerShell命令
但是我们可以从批处理文件运行powershell
,然后使用-command
参数运行启动进程
我们使用Start Process
运行powershell
(再次)并在批处理文件中将脚本提升为Admin:-ArgumentList'-File C:\folder\psfile.ps1'-Verb RunAs
时运行脚本:
powershell -Command "&{ Start-Process powershell -ArgumentList '-File C:\folder\psfile.ps1' -Verb RunAs}"
…基本上,您正在使用Powershell运行Powershell。第二个实例被提升为Admin,正在使用这些权限运行脚本
详细说明:
Start Process
可用于运行程序,并且还具有参数-Verb RunAs
,该参数将程序提升为以管理员身份运行
我们不能从批处理文件调用启动进程
,因为它是PowerShell命令
但是我们可以从批处理文件运行powershell
,然后使用-command
参数运行启动进程
我们使用Start Process
运行powershell
(再次)并在脚本提升为Admin时运行脚本:-ArgumentList'-File C:\folder\psfile.ps1'-Verb RunAs
我已经完成了这一步。powershell-noprofile-command“&{Start Process powershell-ArgumentList'-NoProfile-File%path%Resources\Found\WindowsSecurity.ps1'-Verb RunAs}“非常感谢您的帮助!您能再解释一下吗?:DGlad如果您对我的回答满意,我可以帮您。谢谢您的好意。我已经了解到这一点了。powershell-NoProfile-command”&{Start Process powershell-ArgumentList'-NoProfile-File%path%Resources\Found\WindowsSecurity.ps1'-Verb RunAs}“非常感谢您的帮助!您能再解释一下吗?:DGlad如果您对我的回答满意,我可以帮您。谢谢您的好意。