Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
mrt mrt is offline
external usenet poster
 
Posts: 70
Default Is the user Administrator

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Is the user Administrator

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Is the user Administrator


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Is the user Administrator


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   Report Post  
Posted to microsoft.public.excel.programming
mrt mrt is offline
external usenet poster
 
Posts: 70
Default Is the user Administrator

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Is the user Administrator

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 214
Default Is the user Administrator

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   Report Post  
Posted to microsoft.public.excel.programming
mrt mrt is offline
external usenet poster
 
Posts: 70
Default Is the user Administrator

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Is the user Administrator

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   Report Post  
Posted to microsoft.public.excel.programming
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








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I tell Excel that I am the administrator? Kevin Excel Discussion (Misc queries) 2 August 15th 09 12:20 AM
Administrator Not2Smart New Users to Excel 1 October 1st 08 06:41 PM
Administrator rights whatzzup Excel Discussion (Misc queries) 3 September 22nd 08 02:52 PM
need to change system administrator settings tbolen Excel Discussion (Misc queries) 0 March 8th 07 09:34 PM
I do not have access to a folder and I am the administrator how d. bocathunder Excel Discussion (Misc queries) 4 January 22nd 05 10:53 PM


All times are GMT +1. The time now is 12:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"