-
Jan 5th, 2009, 09:11 AM
#1
Thread Starter
Hyperactive Member
[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?
-
Jan 5th, 2009, 02:04 PM
#2
New Member
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
-
Jan 5th, 2009, 02:59 PM
#3
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.
-
Jan 5th, 2009, 04:04 PM
#4
Thread Starter
Hyperactive Member
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!
-
Jan 6th, 2009, 06:55 AM
#5
Re: How to determine if user is administrator?
-
Jan 6th, 2009, 10:17 AM
#6
Thread Starter
Hyperactive Member
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.
-
Jan 6th, 2009, 11:29 AM
#7
Addicted Member
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.
-
Jan 6th, 2009, 04:23 PM
#8
Re: How to determine if user is administrator?
I completely misread the query. Do you mean:
vb Code:
Option Explicit
Dim objNetwork As Object
Dim objGroup As Object
Dim objUser As Object
Dim strUser As String
Dim strComputer As String
Dim strDomain As String
Private Sub Form_Click()
strUser = InputBox("Enter the User name to check", "Admin test")
On Error GoTo errUsername
Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
If (objGroup.IsMember(objUser.AdsPath) = True) Then
MsgBox strUser & " IS an admin", vbInformation + vbOKOnly, "Admin test"
Else
MsgBox strUser & " IS NOT an admin", vbCritical + vbOKOnly, "Admin test"
End If
Exit Sub
errUsername:
MsgBox "Error processing user name", vbCritical + vbOKOnly, "Admin test"
End Sub
Private Sub Form_Load()
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
strDomain = objNetwork.UserDomain
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
End Sub
-
Jan 6th, 2009, 08:30 PM
#9
Thread Starter
Hyperactive Member
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.
-
Jan 7th, 2009, 04:55 AM
#10
Re: How to determine if user is administrator?
Actually, you should be able to substitute "strComputer" for "strDomain".
Originally Posted by schoolbusdriver
Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
[/HIGHLIGHT]
-
Jan 7th, 2009, 05:58 AM
#11
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
-
Jan 7th, 2009, 12:22 PM
#12
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|