提升而无提示-动词runas启动过程 [英] elevate without prompt - verb runas start-process

查看:151
本文介绍了提升而无提示-动词runas启动过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能无法实现,但是我正在从命令行运行.ps1 powershell脚本,它需要以特权提升的方式运行,而不能或绕过任何UAC提示.

This may not be possible, but I'm looking to run a .ps1 powershell script from a command line, it needs to be run with Elevated privileges, without or bypassing any UAC prompts.

这是从脚本编写的角度来看的,没有用户交互.因此,不能选择CMD或Powershell的以管理员身份运行".无法单击任何UAC提示,因为这些提示很可能会从视图中隐藏.

This is from a scripting perspective, with no user interaction. So "Run as administrator" for CMD or Powershell is not an option. There cannot be any UAC prompts to click on as these will most likely be hidden from view.

我的命令像这样开始-

powershell.exe -executionpolicy bypass -file .\remove-default-apps.ps1

这将启动.ps1,但脚本最终将失败,因为脚本中的命令需要提升(Get-AppxPackage | Remove-AppxPackage)

This would launch the .ps1 fine, but the script would ultimately fail, as the commands in the script require elevation (Get-AppxPackage | Remove-AppxPackage)

我的下一个尝试是使用Powershell通过-

My next attempt was using Powershell to run the script using -

Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File MyScript.ps1' -Verb RunAs

但是仍然提示提升. 我可以从非高架cmd窗口手动复制运行脚本的错误,但是以高架运行它可以正常工作.

But still this prompts for elevation. I can replicate the errors running the script from a non-elevated cmd window manually, but running elevated it works fine.

有人知道这是否完全可能吗?或有任何提示可指示我正确的方向,我尝试了许多其他方法(psexec,计划任务..),但无法实现.

Anyone know if this is at all possible? Or have any tips to point me in the right direction, Ive tried a lot of other methods (psexec, scheduled task..) but am unable to achieve this.

推荐答案

这是设计使然.如果可以通过某种方法忽略UAC,则将扼杀UAC的意义.每个恶意软件都会在没有提示的情况下自行升级,就像UAC之前的荒野西部一样.

This is by design. If UAC could be ignored in some method, it would kill the point of UAC. Every malicious piece of software would escalate itself without prompting, just like the wild west before UAC.

使用海拔高度,您可以将其他东西设置为升高运行,无论是计划任务"还是其他.在企业范围内运行这类事情的最常见方法是将配置管理(SCCM,LANDesk,Puppet,Salt等)与代理一起使用,或通过PSRemoting/PSexec远程运行. (请注意,首先必须使用管理员权限来安装代理程序)

With elevation you can set other things to run elevated, whether Scheduled Tasks or otherwise. The most common thing to run these sorts of things enterprise wide is by using configuration management (SCCM, LANDesk, Puppet, Salt, etc) with an agent or to run remotely via PSRemoting/PSexec. (Note the agents have to be installed with admin rights in the first place)

对于删除已调配的软件包,这似乎是在映像时要完成的任务.可以在部署之前直接从WIM中将其删除,或者在将映像放置在WinPE中之后在任务序列任务中将其删除,或者在SysPrep之前将其删除.我偏爱第二种方法,将所有成像任务都保持在MDT中以编程方式进行,并且具有接近默认的Windows图像.

As for the removing provisioned packages, that seems like a task to be done at image time. Either removing it straight from the WIM prior to deploying, removing it in a Task Sequence task after the image has been laid down while still in WinPE, or removing prior to SysPrep. I'm partial to the 2nd method, and keeping all of my imaging tasks programmatic in MDT and having as close to a default Windows image.

如果您不希望出现提示,则可以关闭UAC(或设置为从不通知Win8 +).如果您要在多台计算机上执行此操作,则可以通过组策略来完成.但这并不明智.

If you don't want the prompt, you can turn UAC off (or set to never notify etc Win8+). That can be done by Group Policy, if you are looking to do on many computers. However that would not be wise.

这篇关于提升而无提示-动词runas启动过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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