Thanks a lot for these inputs. I've modified KeepITcool's code so that it
completely matches my needs + used the Environ function to avoid using the
GetUserName API function (is that really efficient?). I copied the code below.
I only tried it on an XP machine. It still needs to be tested on other
systems including NT 4.0. If anyone can do it, that would allow to have a
nice and consise piece of code, thanks to KeepItCool.
'netapi32
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)
'returns 0 if admin, 1 if user, 2 if guest
Public Function UserType() As Byte
Dim lLen&, lpBuf&, aUI1&(0 To 7)
Dim sUser$
'UserType = 0 'win95/98/Me cant limit userrights
If Not Application.OperatingSystem Like "*32* NT *" Then Exit Function
lLen = 255
sUser = Environ("Username")
If Environ("Username") < "" Then
sUser = sUser & vbNullChar & Space(lLen - Len(sUser) - 1)
'optional: type servername...
'servername: here local computer as sServer set to null
If (NetUserGetInfo(StrPtr(vbNullString & vbNullChar), StrPtr(sUser),
1, lpBuf) = 0&) Then
Call CopyMemory(aUI1(0), ByVal lpBuf, 32)
Call NetApiBufferFree(ByVal lpBuf)
UserType = 2 - aUI1(3)
End If
End If
End Function
"keepITcool" wrote:
I've just had a look at Randy Birch's solution
on VBnet as mentioned by Bob.
http://vbnet.mvps.org/code/network/isadministrator.htm
I'm wondering if my simple code achieves the same results :)
Let me know please!
keepITcool
< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool
keepITcool wrote:
I've been playing a bit.. and I hope you have NT/XP machines :)