Testing the application for administrative rights to execute VB.NET

I want the sure shot method to check if the application was launched through UAC and has full administrator rights. I used to think about creating a folder in C: \ Windows \ for testing, but running it on other computers was unsuccessful!

The UAC window grants all administrator rights to the computer to do anything (including creating folders and creating files where they need rights), and also ensures that any child program, so-called or created, also has the same rights as the ancestor.

Is there a surefire way to check if my application has all the administrator rights that I can get from a user during application startup or not? If so, I would be happy to receive a piece of code!

Thanks in advance

+8
windows uac
source share
1 answer

FROM#:

using System.Security.Principal; ... var identity = WindowsIdentity.GetCurrent(); var principal = new WindowsPrincipal(identity); bool isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator); 

VB.Net:

 Imports System.Security.Principal ... Dim identity = WindowsIdentity.GetCurrent() Dim principal = new WindowsPrincipal(identity) Dim isElevated as Boolean = principal.IsInRole(WindowsBuiltInRole.Administrator) 
+18
source share

All Articles