Showing the UAC prompt in PowerShell if the action requires elevation

前端 未结 3 2027
轻奢々
轻奢々 2020-12-08 16:48

I have a simple PowerShell script to stop a process:

$p = get-process $args
if ( $p -ne $null )
{
$p | stop-process
$p | select ProcessName, ID, HasExited, C         


        
3条回答
  •  广开言路
    2020-12-08 17:17

    This script sectio check for the Medium Mandatory level token (non elevated admin) and restarts the script elevated.

    if ($Mygroups -match ".*Mandatory Label\\Medium Mandatory Level") {
      #non elevated admin: elevating
      write-host "Elevate"
      start-process powershell -Argumentlist "$PSCommandPath  -Yourargument $Youragumentvalue" -verb runas -Wait 
      exit
    }
    

提交回复
热议问题