VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 340,158 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 4,068 people online right now. Registration is fast and FREE... Join Now!




Check if the user is an administrator

Check if the user belongs to the administrators group.

Submitted By: RodgerB
Actions:
Rating:
Views: 6,138

Language: VB.NET

Last Modified: December 23, 2007
Instructions:
1) Copy and paste the function into a class.
2) Read how to call the function.

Snippet


  1. ''' <summary>
  2. ''' Check if the user belongs to the administrators group.
  3. ''' </summary>
  4. ''' <returns>True if the user belongs to the administrators group.</returns>
  5. ''' <remarks></remarks>
  6. Public Function isAdministrator() As Boolean
  7.     ' Check if the user is authenticated before continuing.
  8.     If My.User.IsAuthenticated Then
  9.         ' If the user is in the administrators group.
  10.         If My.User.IsInRole("Administrators") Then
  11.             Return True
  12.         End If
  13.     End If
  14.     ' Return false because the user isn't an administrator,
  15.     ' or authenticated.
  16.     Return False
  17. End Function
  18.  
  19. ' Example Usage
  20. MessageBox.Show(isAdministrator())

Copy & Paste


Comments

mejicano 2010-01-31 14:55:35

it never goes into the first IF..... what am i doing wrong? on xp, with autheticated admin account... thanks.


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month