klumsy
klumsy

Reputation: 4261

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

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#.

Upvotes: 2

Views: 836

Answers (2)

Shay Levy
Shay Levy

Reputation: 126722

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/

Upvotes: 0

quetzalcoatl
quetzalcoatl

Reputation: 33506

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.

Upvotes: 0

Related Questions