Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Randy Birch has a VB solution for the current user which you could modify.
It is at vbnet.mvps.ortg, search on How to Determine if the Current User is a Member of Administrator -- HTH RP "MrT" wrote in message ... 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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 ?B?TXJU?= wrote: 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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 :) |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 :) |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tk,
Environ for username IS faster. Added Environ OS for NT testing Added conditional compile for Win32 (vs Mac and Win16) Further condensing it.. <g Public Function UserType() As Byte 'returns 0 if admin, 1 if user, 2 if guest ' 255 for errors 'Author : keepITcool Excel.Programming ' UserType = 255 #If Win32 Then 'only run on 32bit Windows Dim lpBuf&, sUser$, lPriv& If Environ$("OS") < vbNullString Then 'OS env variable only found on NT/2k/XP machines sUser = Environ$("Username") & vbNullChar If NetUserGetInfo(0, StrPtr(sUser), 1, lpBuf) = 0 Then Call CopyMemory(lPriv, ByVal lpBuf + 12, 4) Call NetApiBufferFree(lpBuf) UserType = 2 - lPriv End If Else 'win95/98/Me cant limit userrights UserType = 0 End If #End If End Function keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool ?B?TXJU?= wrote: 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 :) |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Yeah, use early binding. Go to Project | References and put a check next to
Windows Script Host Object Model If it is not there, browse for the file wshom.ocx (c:\windows\system32 on my machine)) and open it. Then change the code to Sub WhichGroup() Dim WSHNet As WshNetwork Set WSHNet = New WshNetwork With WSHNet 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 -- HTH RP "MrT" wrote in message ... 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 |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I tell Excel that I am the administrator? | Excel Discussion (Misc queries) | |||
Administrator | New Users to Excel | |||
Administrator rights | Excel Discussion (Misc queries) | |||
need to change system administrator settings | Excel Discussion (Misc queries) | |||
I do not have access to a folder and I am the administrator how d. | Excel Discussion (Misc queries) |