检查升高的进程状态?

Sum*_*ngh 3 windows powershell

我想找到一种方法来查明进程是否以提升的方式运行或不使用 Powershell。

使用案例:能够以本地域用户的身份以更高的权限运行控制面板任务,例如添加或删除程序。

任何帮助将不胜感激。

#Start add or remove as admin
start-process appwiz.cpl -verb runas

#Check if path exists. Answer is Yes, so process is NOT elevated
get-wmiobject -class win32_process | select-object -properties name, path
Run Code Online (Sandbox Code Playgroud)

Bil*_*art 8

这是两个常见的选项:

  1. #requires -RunAsAdministrator在脚本中使用该行(需要 PowerShell 3.0 或更高版本)。如果您在脚本顶部使用此行,它将引发终止错误,并且如果当前进程未提升,则不会执行。

  2. 使用如下代码检测当前进程是否提升:

    $IsElevated = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
    
    Run Code Online (Sandbox Code Playgroud)