gpt4 book ai didi

windows - 检查提升的进程状态?

转载 作者:行者123 更新时间:2023-12-02 00:34:05 26 4
gpt4 key购买 nike

我想找到一种方法来查明进程是否以提升的方式运行或未使用 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

最佳答案

这是两个常用的选项:

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

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

    $IsElevated = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

关于windows - 检查提升的进程状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50492495/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com