View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Michel Pierron Michel Pierron is offline
external usenet poster
 
Posts: 214
Default Is the user Administrator

Hi MrT;
In complement of the message of Bob, go to Project | References and put a
check next to Active DS Type Library. If it is not there, browse for the
file (c:\windows\system32\activeds.tlb) and open it.

Then change the code to
Sub WhichGroup()
Dim WSHNet As WshNetwork
Set WSHNet = New WshNetwork
With WSHNet
MsgBox IsAdmin(.UserDomain, .UserName)
End With
End Sub

Private Function IsAdmin(strDomain, strUser) As Boolean
Dim Group As IADsGroup, User As IADsUser
Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
Set Group = GetObject("WinNT://" & strDomain & "/Administrators, group")
IsAdmin = Group.IsMember(User.ADsPath)
End Function

Regards,
MP

"MrT" a écrit dans le message de
...
Congrats Michel ... even more concise. But I have a time constraint and

your
solution is much slower than the solution of KeepItcool (with my

contribution
for a few milliseconds ;-)), because of the call to
GetObject("WinNT://" & strDomain & "/" & strUser & ",user")

As it seems you are a wizard, may be you can find a faster solution?

Regards,

MrT

"Michel Pierron" wrote:

Hi MrT;
You can try:
Sub WhichGroup()
With CreateObject("Wscript.Network")
GetUserGroup .UserDomain, .UserName
End With
End Sub

Sub GetUserGroup(strDomain, strUser)
Dim Group As Object, User As Object
Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
For Each Group In User.Groups
MsgBox Group.Name
Next
Set Group = Nothing: Set User = Nothing
End Sub

MP

"MrT" a écrit dans le message de
...
Dear Colleagues,

Do you know a way to determine if the group to the which the user

belongs
(administrator, guest, standard user, ...)?

I tried using Environ but could not find a solution this way.

Thanks for your help,

MrT