I've been playing a bit.. and I hope you have NT/XP machines
This will tell you if he has admin rights on the current
machine (optionally you may enter a server name)
Officially it should go into a data structure
of type User_info_1 but i've tried to make it
the code as simple as possble and used an array
of longs instead.
Enumerating the Usergroups was getting a bit more complex..
Option Explicit
'ADVAPI32
Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Private Declare Function NetUserGetInfo Lib "netapi32" ( _
ByVal ServerName As Long, ByVal UserName As Long, _
ByVal Level As Long, ByRef ptrBuffer As Long) As Long
Private Declare Function NetApiBufferFree Lib "netapi32" ( _
ByVal ptrBuffer As Long) As Long
'KERNEL32
Private Declare Sub CopyMemory Lib "kernel32" Alias _
"RtlMoveMemory" (Destination As Any, Source As Any, _
ByVal Length As Long)
Function IsAdmin() as Boolean
Dim lLen&, lpBuf&, aUI1&(0 To 7)
Dim sUser$, sServer$
If Not Application.OperatingSystem Like "*32* NT *" Then
IsAdmin = True 'win95/98/Me cant limit userrights
Exit Function
End If
lLen = 255
sUser = Space(lLen)
If GetUserName(sUser, lLen) Then
'optional: type servername...
sServer = vbNullString & vbNullChar
If (NetUserGetInfo(StrPtr(sServer), StrPtr(sUser), 1, lpBuf) = 0&)
Then
Call CopyMemory(aUI1(0), ByVal lpBuf, 32)
Call NetApiBufferFree(ByVal lpBuf)
IsAdmin = (aUI1(3) = 2)
End If
End If
End Function
keepITcool
< email : keepitcool chello nl (with @ and .) >
< homepage:
http://members.chello.nl/keepitcool >