Results 1 to 3 of 3

Thread: Is the logged in user an administrator?

  1. #1

    Thread Starter
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616

    Is the logged in user an administrator?

    How (in VB.Net) do I find out if the logged in user is an administrator?
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  2. #2
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    Cape Cod, US
    Posts
    292
    If you mean local admin, you should be able to get what you need from this sample.
    Check out where I invoke IsMember.

    Code:
        Private Function AddUserToWinGroup(ByVal szGroup As String, ByVal szUser As String) As Boolean
    
            Const MODULE_NAME = "AddUserToWinGroup"
            Const ADSI_PROVIDER = "WinNT://"
    
            Dim szPathGroup As String = ADSI_PROVIDER & m_szLocalMachine & "/" & szGroup & ",group"
    
            ' the username comes in looking like <domain>\<username>
            ' we need it to look like <domain>/<username> for ADSI to work
            Dim szPathUser As String = ADSI_PROVIDER & szUser.Replace("\", "/") & ""
    
            Try
                Dim entryGroup As New DirectoryServices.DirectoryEntry(szPathGroup)
                '            Dim entryUser As New DirectoryServices.DirectoryEntry(szPathUser)
    
                ' only add the user if not already a member
                If Not entryGroup.Invoke("ismember", szPathUser) Then
                    entryGroup.Invoke("add", szPathUser)
                End If
            Catch
                m_szLastError = MODULE_NAME & ": " & Err.Description
                Return False
            End Try
    
            Return True
    
        End Function

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    VB Code:
    1. Dim wp As New Security.Principal.WindowsPrincipal(Security.Principal.WindowsIdentity.GetCurrent)
    2.         MsgBox(wp.IsInRole(Security.Principal.WindowsBuiltInRole.Administrator), , wp.Identity.Name)
    3.         'for none built in groups just use a string (domain\group)
    4.         MsgBox(wp.IsInRole("MHC\PS Admins"), , wp.Identity.Name)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width