Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

CODE 1:

If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
   End
End If

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.

  • Administrators
Posted

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)

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...