Check if the user is an administrator

This function will return a boolean result of whether the user is enrolled in the administrators group or not.

VB.NET

''' <summary>
''' Check if the user belongs to the administrators group.
''' </summary>
''' <returns>True if the user belongs to the administrators group.</returns>
''' <remarks></remarks>
Public Function isAdministrator() As Boolean
    ' Check if the user is authenticated before continuing.
    If My.User.IsAuthenticated Then
        ' If the user is in the administrators group.
        If My.User.IsInRole("Administrators") Then
            Return True
        End If
    End If
    ' Return false because the user isn't an administrator,
    ' or authenticated.
    Return False
End Function

' Example Usage
MessageBox.Show(isAdministrator())

See Also

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License