Check for elevated rights in .NET 8

07/12/2022
.NET.NET 8C#

A recent API was added to the framework under the name "Add API to check if process had administrator privileges", which adds this API to the framework itself.

And it is fairly simple:

var hasPrivilegedRights = Environment.IsPrivilegedProcess;

Yes, that is all. The new call lives in the System.Environment class. That works independently of the underlying OS (as long as the underlying OS supports the .NET runtime). Currently (as of today - 7. December 2022) there is no API that grants you privileged rights nor an API that drops them. But there are ideas and smaller proposals for that. So let's see what the future brings.

4
An error has occurred. This application may no longer respond until reloaded. Reload x