Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 18-12-2008
Member
 
Join Date: Nov 2008
Posts: 21
VB script - List all user groups Help

VBS - List all user groups

Hello forum

I have plans to replace our login script (currently written in Kix) with a VBS script.This script (the new) is about to be completed. But in my tests, I realized that the code that I use to list the groups, lists only groups in the "member" of the properties of the user.

The code is as follows:

Code:
Select All 
Set ADSysInfo = CreateObject("ADSystemInfo") 
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName) 
strGroupsUser = LCase(Join(CurrentUser.MemberOf)) 
wscript.echo strGroupsUser
Using the nesting groups (AGG-DL-P), I link access to certain shares to groups that do not appear on this tab, but the user is a member (through the interlocking groups) . Under Server 2003, the utility DsGet (with the proper parameters) can make this work.

Beginner in this language, I would like to know if there is a piece of code VBS, to be able to retrieve the list of all groups which the user is a member.
Thank you in advance for your help.

Note: If there is another way to do what I want to do, I am open to any proposal
Reply With Quote
  #2  
Old 18-12-2008
Member
 
Join Date: May 2008
Posts: 115
Re: VB script - List all user groups Help

Knowing that as a group, you can also access the memberOf property, it will have set up a recursive code.

This could give something like this:

Code:
Select All 
Set ADSysInfo = CreateObject("ADSystemInfo") 
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName) 
strGroupsUser = LCase(Join(CurrentUser.MemberOf)) 
For each grp in CurrentUser.MemberOf 
seekGrp(grp) 
Next 

wscript.echo strGroupsUser 

Sub seekGrp(groups) 
Set objG = GetObject("LDAP:\\cn=" & groups & ",DC=...") 
For Each grp in objG.MemberOf 
strGroupsUser = strGroupsUser & grp 
seekGrp(grp) 
Next 
End Sub

A test, I wrote without accepting the execution. But I think the idea is there.
Reply With Quote
  #3  
Old 18-12-2008
Member
 
Join Date: Nov 2008
Posts: 21
Re: VB script - List all user groups Help

Thanks For your Quick Reply
I am studying your code.

To begin with, I do not know if it's a mistake, but I replaced this

Code:
 
Select All 
Sub seekGrp(groups) 
Set objG = GetObject("LDAP:\\cn=" & groups & ",DC=...")
by

Code:
Select All 
Sub seekGrp(groupe) 
Set objG = GetObject("LDAP://"& groups)
as group returns a value of this type = CN = name of the group, OR = xxx, xxx OR = DC = foo, DC = lan

Once this change of fact, when I come to the second loop, I get an error:
Error: This object is not a collection
Code: 800A01C3
And here I do not know how to solve this problem.
Reply With Quote
  #4  
Old 18-12-2008
Member
 
Join Date: May 2008
Posts: 115
Re: VB script - List all user groups Help

For the first remark, that is what I said: I have not tested

Otherwise, I think the problem is triggered, occurs when the group does not belong to another group. We can solve this with the following correction:

Code:
Select All 
Sub seekGrp(groupe) 
Set objG = GetObject("LDAP:\\cn=" & groups & ",DC=...") 
if IsArray(objG.MemberOf)   then 
For Each grp in objG.MemberOf 
strGroupsUser = strGroupsUser & grp 
seekGrp(grp) 
Next 
end if 
End Sub
Reply With Quote
  #5  
Old 18-12-2008
Member
 
Join Date: Nov 2008
Posts: 21
Re: VB script - List all user groups Help

It's perfect, the code that you did work well.

I still have 1 questions With this code, I can list the groups that are in the "Member" and groups that I describe as "second level". If I want to go further in search of groups I suppose, I must create another loop, but the place? I met the day code (code to search for a group of "" the first and second level "depending on the user logged in):

Code:
Select All 
Set ADSysInfo = CreateObject("ADSystemInfo") 
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName) 
strGroupsUser = LCase(Join(CurrentUser.MemberOf)) 
For each grp in CurrentUser.MemberOf 
seekGrp(grp) 
Next 

wscript.echo strGroupsUser 

Sub seekGrp(groupe) 
Set objG = GetObject("LDAP://"& groupe) 
if IsArray(objG.MemberOf) then 
For Each grp in objG.MemberOf 
strGroupsUser = strGroupsUser & vbcrlf & LCase(grp) 
seekGrp(grp) 
Next 
End if 
End Sub
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "VB script - List all user groups Help"
Thread Thread Starter Forum Replies Last Post
VB Script returns all group memberships for a user EXCEPT Exchange Dist groups SecurityGuy Active Directory 6 01-02-2011 04:26 PM
Script to create multiple groups Saphire Active Directory 1 18-08-2008 11:51 PM
Ldap query to list groups a user is a member of? SKREECH Active Directory 1 24-02-2008 08:30 PM
Getting a list of users in global and local groups. Joe Windows Server Help 10 06-09-2007 11:02 AM
Script/regedit: Explorer-View-Arrange Icons by-Show In Groups... prash_mate Windows XP Support 1 17-05-2007 12:57 AM


All times are GMT +5.5. The time now is 08:42 AM.