How to detect if a specific process is elevated using dotnet or powershell

753 views Asked by At

How can I detect if a specific process is elevated or not. This process is different than the process where my code is running. I'd like to be able to do this from with PowerShell or C#.

2

There are 2 answers

2
Shay Levy On

Maybe this can help

Get-Process |
Add-Member -Name Elevated -MemberType ScriptProperty -Value {if ($this.Name -in @('Idle','System')) {$null} else {-not $this.Path -and -not $this.Handle} } -PassThru |
Format-Table Name,Elevated

From http://www.powershellmagazine.com/2013/03/29/pstip-detecting-if-a-certain-process-is-elevated/

0
quetzalcoatl On

Please try out this answer: https://stackoverflow.com/a/4497572/717732

That UacHelper will need some minor changes. Like, IsProcessElevated uses OpenProcessToken on CurrentProcess - you will need to change the IsProcessElevated fo a function and make the Process a parameter, so you can inspect any, not just current one.

In general, this class does all that you'd need to. It inspects the security properties assigned to the process. I think that code speaks by itself.

BTW. If you think that code is OK for your needs, please mark your question as 'duplicate' of that one - it will help others in finding that code.