使用powershell脚本来终止进程但访问deined

时间:2016-06-06 00:56:52

标签: powershell

我需要使用powershell脚本来终止进程,但访问被拒绝。如何获得PowerShell脚本的管理员?另外,我不想手动输入管理员帐户和密码。 Get-Admin过程需要自动完成。我该怎么办?

2 个答案:

答案 0 :(得分:1)

您需要删除脚本或控制台提示,才能使用"以管理员身份运行"选项。关于如何在脚本中执行此操作的good example script can be found here

链接中提供的脚本只是让用户运行脚本并验证是否已经过了当前会话。如果不是,你必须打开一个以杀死进程。如果你在Windows上,你也会处理UAC,如果运行它的用户没有本地管理员权限,你将被提示输入凭据。

验证执行帐户是否为admin的代码片段:

# Get the ID and security principal of the current user account
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)

# Get the security principal for the Administrator role
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
$myWindowsPrincipal.IsInRole($adminRole)

您可以找到get elevated permissions here的其他几个选项。

答案 1 :(得分:0)

就做

start-process pwsh -Verb RunAs

start-process powershell -Verb RunAs

让自己高高的壳。然后运行所需的命令

相关问题