Results 1 to 12 of 12

Thread: [RESOLVED] How to determine if user is administrator?

  1. #1

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Resolved [RESOLVED] How to determine if user is administrator?

    I want to check if a particular local user is in the Administrators group. The computers are not in a domain so I'm only concerned with a local user. The username is local1 and I want to determine if it is a local administrator whether or not I'm logged in as local1. Does anyone know how I can do this?

  2. #2
    New Member
    Join Date
    Jan 2009
    Posts
    1

    Re: How to determine if user is administrator?

    use this :

    Private Declare Function IsUserAnAdmin Lib "shell32" () As Long

    Private Sub Form_Load()
    If IsUserAnAdmin() = 1 Then
    msgbox "Admin"
    end if
    End Sub

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: How to determine if user is administrator?

    Of course IsUserAnAdmin() only tells whether or not the process has elevated rights, not what groups the user belongs to.

  4. #4

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Re: How to determine if user is administrator?

    IsUserAnAdmin works perfect for me, except that it seems to only work with the currently logged in user. I want to be able to test if the user "local1" is an admin even if I'm not logged in as local1. Is there a way to do this?

    Thanks!

  5. #5
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: How to determine if user is administrator?


  6. #6

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Re: How to determine if user is administrator?

    Looks like NetUserGetInfo is for use with a domain because the call requires a server name. Unfortunately these computers are not in a domain.

  7. #7
    Addicted Member
    Join Date
    Apr 2008
    Posts
    198

    Re: How to determine if user is administrator?

    y dont u take this list from the active directory?
    u can control it and u can get any info of the user....
    IT CTO & System Administrator.

  8. #8
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: How to determine if user is administrator?

    I completely misread the query. Do you mean:
    vb Code:
    1. Option Explicit
    2.  
    3. Dim objNetwork As Object
    4. Dim objGroup As Object
    5. Dim objUser As Object
    6. Dim strUser As String
    7. Dim strComputer As String
    8. Dim strDomain As String
    9.  
    10. Private Sub Form_Click()
    11.    strUser = InputBox("Enter the User name to check", "Admin test")
    12.    
    13.    On Error GoTo errUsername
    14.    Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
    15.    If (objGroup.IsMember(objUser.AdsPath) = True) Then
    16.       MsgBox strUser & " IS an admin", vbInformation + vbOKOnly, "Admin test"
    17.    Else
    18.       MsgBox strUser & " IS NOT an admin", vbCritical + vbOKOnly, "Admin test"
    19.    End If
    20.    Exit Sub
    21. errUsername:
    22.    MsgBox "Error processing user name", vbCritical + vbOKOnly, "Admin test"
    23. End Sub
    24.  
    25. Private Sub Form_Load()
    26.    Set objNetwork = CreateObject("Wscript.Network")
    27.    strComputer = objNetwork.ComputerName
    28.    strDomain = objNetwork.UserDomain
    29.    Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
    30. End Sub

  9. #9

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Re: How to determine if user is administrator?

    I cannot take the list from the Active Directory because as I said, they do NOT have a domain; hence, they do not have Active Directory.

    Schoolbusdriver, I'll see if that code can be adapted to work for local users.

  10. #10
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: How to determine if user is administrator?

    Actually, you should be able to substitute "strComputer" for "strDomain".
    Quote Originally Posted by schoolbusdriver
    Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
    [/HIGHLIGHT]

  11. #11
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: How to determine if user is administrator?

    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  12. #12

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Re: How to determine if user is administrator?

    koolsid, that would work if I was logged on as local1, but I want to be able to tell if local1 is an admin even if I'm not logged in as local1.

    Schoolbusdriver, that works perfect! Thanks!

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