Detect if my user is admin?

ADO DOT NET

Centurion
Joined
Dec 20, 2006
Messages
160
Hi,
I want to check if my user is admin or not?
IF not, give him a nice error and End my application!
I only need to run this in Windows XP, Vista and Server 2003 !
I have these 2 codes:
Visual Basic:
CODE 1:

If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
    End
End If
Visual Basic:
CODE 2:

Dim wp As New WindowsPrincipal(WindowsIdentity.GetCurrent())
If wp.IsInRole(WindowsBuiltInRole.Administrator) = False Then
    End
End If
I just wanna know which one is correct and better to use for me?
What's the different between these two?
Thank you.
 
Looking at the il with ildasm it appears that the My.User.... function ultimately calls the WindowsPrincipal.IsInRole method anyway.

Other than that I can't really see any major difference, personally I would tend to avoid the My.... methods simply because I use both vb and c# so I try to use functionality that is present in both (less for me to remember that way)
 
Back
Top