Page 1 of 1 1
Topic Options
#111384 - 2004-01-07 10:38 AM how to find user is member of group ??
futureline Offline
Fresh Scripter

Registered: 2003-12-12
Posts: 10
How can I find out in what group a user is located.
What I want to set is a variable $group and set it with the name of the group the user is in so I get
$group=Domain Users

Can someone provide me a sample code on how to do this.

Top
#111385 - 2004-01-07 11:00 AM Re: how to find user is member of group ??
Mfarah Offline
Fresh Scripter

Registered: 2003-09-24
Posts: 27
Loc: London
Hi

Here is a script I use for mapping drives based on group membership. It works in conjunction with an .ini file and should give you some indiciation of how this variable works.

Script;
Code:
 

For Each $group in Split(ReadProfileString(@scriptdir+'\groups.ini','',''),Chr(10))
If $group AND InGroup($group)
For Each $drive In Split(ReadProfileString(@scriptdir+'\groups.ini',$group,''),Chr(10))
If $drive
$resource=readprofilestring(@scriptdir+'\groups.ini',$group,$drive)
$rc=execute('$$resource='+$resource)
Use $drive+':' /delete /persistent
Use $drive+':' $resource
;Use $drive+':' ReadProfileString(@scriptdir+'\groups.ini',$group,$drive)
EndIf
Next
EndIf
Next




.INI File;

Code:
 

[HAP Abingdon]
I= \\hpsfp04\read_wp
j= \\hpsnfs01\read_forms

[Domain Users]
I= \\server01\share
J= \\server02\share




Top
#111386 - 2004-01-07 11:34 AM Re: how to find user is member of group ??
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Read up on "EnumGroup()" in the manual, which includes a simple example.
Top
#111387 - 2004-01-07 02:35 PM Re: how to find user is member of group ??
futureline Offline
Fresh Scripter

Registered: 2003-12-12
Posts: 10
Oke but what I need is the exact group name. Not a loop.

Here is my code:
;***********************************************************************
;**
;** Connect GroupShares to Drives
;**
Function COnnectGroupDrives()

;******************************
; GroupShares
;******************************
If Exist($FileLocation + "\shares.ini")
If $group<>""
For $x = 1 to 10
$DriveDefinition = ReadProfileString($FileLocation + "\shares.ini", $group, "drive" + $x)
If @ERROR = 0
If $DriveDefinition<>""
ConnectShare($DriveDefinition)
EndIf
Else
Return
EndIf
Next
EndIf
EndIf
EndFunction

My Shares.ini

[Domain Users]
Drive1="P:, \\SERVER\Management$, Management"
Drive2="Q:, \\SERVER\TechnicalData$, Quality"

Thats why i need the exact group. The script must do a look a see that i am in "Domain Users" an give me the shares.

Hope this helps to explain my problem.

PS. The Code is done by someone else of a kix forum.I am just using it.

Top
#111388 - 2004-01-07 03:12 PM Re: how to find user is member of group ??
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Oke but what I need is the exact group name. Not a loop.




A login is going to be a member of more than one group. You need the loop so that you can check for file mappings for all the groups that the login is a member of.

Call the ConnectGroupDrives() for each group that is returned.

Top
#111389 - 2004-01-07 03:45 PM Re: how to find user is member of group ??
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
There's even a UDF that returns all groups a user is a member of: ArrayEnumGroup() - Creates an array of groups of which the current user is a member
_________________________
There are two types of vessels, submarines and targets.

Top
#111390 - 2004-01-07 04:44 PM Re: how to find user is member of group ??
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Maybe the real question is related to the "Primary Group" and not general group membership. In which case this thread may shed some light.

http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=107908

$Win32Admin.GetUserGroupFromRID($server,$UserInfo.primary_group_id)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#111391 - 2004-01-07 06:32 PM Re: how to find user is member of group ??
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Can you use the code tags when posting code? It will make it much easier to read.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.057 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org