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#.
How to detect if a specific process is elevated using dotnet or powershell
800 Views Asked by klumsy At
2
There are 2 best solutions below
2
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/
Please try out this answer: https://stackoverflow.com/a/4497572/717732
That
UacHelperwill need some minor changes. Like,IsProcessElevatedusesOpenProcessTokenon CurrentProcess - you will need to change theIsProcessElevatedfo a function and make theProcessa 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.