| View previous topic :: View next topic |
| Author |
Message |
Dave Heck Valued Newbie

Joined: 02 Mar 2002 Posts: 34 Location: Union, CT USA
|
Posted: Wed Nov 18, 2009 8:48 pm Post subject: Active Directory Tools |
|
|
I'm looking for an add-on DLL file that will allow me to tap into Active Directory - specifically I'm looking for the ability to check to see if a user is a member of an AD group and then act upon the fact that they are or not. Of course if someone has any suggestions I'm willing to give it a shot.
I've tried using the tool "IFMEMBER.EXE" which will give a Return Code of 1 if they are a member, or 0 if they are not. Unfortunately that is giving inconsistent results sometimes. I've also "piped" the output from the ShowGRPS command to a .TXT file and then loaded it into a List and run through it looking for matches.
Both of these methods seem to work for most of my users I'm checking, but I have this one user whom I am not getting a positive result when checking a group I know she is in. I believe this MAY be related to the number of groups this particular individual is in, but cannot prove it.
Thanks for any and all help,
Dave _________________ Dave Heck
dheck1961@cox.net
Union, Connecticut USA |
|
| Back to top |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Fri Nov 20, 2009 1:51 am Post subject: |
|
|
You can use DSQUERY and DSGET with VDS's PIPE option to accomplish this. These are M$ free tools.
| Code: | %%User = @env(Username)
runh dsquery user -samid %%User | dsget user -memberof,pipe
info @pipe() |
Of course, you can dump the contents of @pipe() into a list and then search the list for what you need. |
|
| Back to top |
|
 |
Dave Heck Valued Newbie

Joined: 02 Mar 2002 Posts: 34 Location: Union, CT USA
|
Posted: Fri Nov 20, 2009 1:08 pm Post subject: Getting an error when I try this |
|
|
When I run it I'm getting the following error:
dsquery failed:'dsget' is an unknown parameter. type dsquery /? for help
I altered the code (see below) by removing the pipe to the dsget command and I do get the user ID, OU, etc. from the dsquery. I'm using VDS6 and running on a Win7 32bit machine right now, but the end result will be run on WinXP SP2 machines - don't know/think this makes a difference....
%%User = @env(Username)
runh dsquery user -samid %%User,PIPE
REM | dsget user -memberof,pipe
info @pipe() _________________ Dave Heck
dheck1961@cox.net
Union, Connecticut USA |
|
| Back to top |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Sat Nov 21, 2009 12:29 am Post subject: |
|
|
Try it with quotes:
| Code: | %%User = @env(Username)
runh "dsquery user -samid "%%User" | dsget user -memberof",pipe
info @pipe() |
You can also test the command itself from a command prompt.
from a cmd prompt type: dsquery user -samid %UserName% | dsget user -memberof
I'll have to look at some of my old AD query code to see if the quotes are necessary or maybe remove the spaces before and after the pipe "|" character. |
|
| Back to top |
|
 |
Dave Heck Valued Newbie

Joined: 02 Mar 2002 Posts: 34 Location: Union, CT USA
|
Posted: Sat Nov 21, 2009 11:07 am Post subject: Working now |
|
|
Hey Aslan - it's now working. When I typed it into a CMD prompt I got the group list for my user. I just put a call to the CMD prompt at the beginning of the RUNH line. It works with and without the quotes
%%User = @env(Username)
runh cmd /c dsquery user -samid %%User | dsget user -memberof,pipe
info @pipe()
Do you know if there is a command line option to check for a specific group? We have an Outlook Add-in that needs to be enabled/disabled depending on whether the user is in an AD group or not. If they are a member of a group called RRC\ReplyAll in AD then I enable it in the registry and disable if they are not a member
I can always dump the results from the @pipe() command into a LIST and loop through it to check, but if you know of something offhand that would be great.
Thanks for your help,
Dave  _________________ Dave Heck
dheck1961@cox.net
Union, Connecticut USA |
|
| Back to top |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Sat Nov 21, 2009 3:11 pm Post subject: |
|
|
Good catch Dave
I looked in my old script and I had to use "cmd /c" also.
You will need to go ahead and dump the results to a list and check for that group.
| Code: | List create,1
%%User = @env(Username)
runh cmd /c dsquery user -samid %%User | dsget user -memberof,pipe
List assign,1,@pipe()
List seek,1,0
If @match(1,"RRC\ReplyAll")
# Put your reg code here to enable add-in
else
# Put your reg code here to disable add-in
end |
Good luck with it  |
|
| Back to top |
|
 |
Dave Heck Valued Newbie

Joined: 02 Mar 2002 Posts: 34 Location: Union, CT USA
|
Posted: Sat Nov 21, 2009 8:20 pm Post subject: good to go |
|
|
Cool...thanks again. I'll modify a subroutine that was set to load the showgrps text and loop through it to use this method/output.
Dave _________________ Dave Heck
dheck1961@cox.net
Union, Connecticut USA |
|
| Back to top |
|
 |
Dave Heck Valued Newbie

Joined: 02 Mar 2002 Posts: 34 Location: Union, CT USA
|
Posted: Sun Mar 14, 2010 12:04 pm Post subject: Follow-up - nested groups |
|
|
Just in case anyone else tries using this....
I've found that this method works well when the user is in a put directly into a group, but it doesn't work for nested groups.
We have a group (All Attorneys) which is made up of other groups (Hartford Attorneys, Boston Attorneys, etc.). If I put the user directly into the "All Attorneys" group then the DSGet/DSQuery shows the user is in the group.
If I put the user into any of the nested groups such as "Hartford Attorneys" it shows them as a member of that group, but doesn't show they are a member of "All Attorneys"
This is really strange because the older method using the IFMember.exe in a DOS batch file DOES get them as a member of the "top level" group even if they are a only a member of a nested group. _________________ Dave Heck
dheck1961@cox.net
Union, Connecticut USA |
|
| Back to top |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Sun Mar 14, 2010 2:00 pm Post subject: |
|
|
Dave to get a recursive list of groups you need to use the "-expand" switch
| Code: | List create,1
%%User = @env(Username)
runh cmd /c dsquery user -samid %%User | dsget user -memberof -expand,pipe
List assign,1,@pipe()
List seek,1,0
If @match(1,"RRC\ReplyAll")
# Put your reg code here to enable add-in
else
# Put your reg code here to disable add-in
end |
Sorry, I should have mentioned that earlier  |
|
| Back to top |
|
 |
Dave Heck Valued Newbie

Joined: 02 Mar 2002 Posts: 34 Location: Union, CT USA
|
Posted: Mon Mar 15, 2010 1:09 pm Post subject: That'll work.... |
|
|
Hi Aslan - thanks for the modification. Working great!
Dave _________________ Dave Heck
dheck1961@cox.net
Union, Connecticut USA |
|
| Back to top |
|
 |
Dave Heck Valued Newbie

Joined: 02 Mar 2002 Posts: 34 Location: Union, CT USA
|
Posted: Tue Mar 16, 2010 12:44 pm Post subject: Just to beat the DSGet/DSQuery horse a bit more..... |
|
|
It appears that the -expand works fine under Windows XP SP2, however under Windows 7 Pro (32bit) the -expand is pulling way too much information and giving inaccurate results.
I checked the version numbers/date-time of DSGet.exe, DSQuery.exe and DSQuery.dll and all are 6.1.7600.16385 7/13/2009 09:14PM
Under Win7 without the -expand I show my user is a member of 50 groups. With the -expand it shows 2274 groups which I would wager is probably the total number of groups in our AD Structure, but don't know for sure. _________________ Dave Heck
dheck1961@cox.net
Union, Connecticut USA |
|
| Back to top |
|
 |
Dave Heck Valued Newbie

Joined: 02 Mar 2002 Posts: 34 Location: Union, CT USA
|
|
| Back to top |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
|
| Back to top |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Sat Mar 20, 2010 7:39 pm Post subject: |
|
|
Also, have you tried using an older version of DSGET? 5.x maybe...
I haven't tried it with Win 7 but it works with Vista
If you have a copy of "VDSDB.DLL" by Tommy Sools, you can query AD just like a SQL database. |
|
| Back to top |
|
 |
Dave Heck Valued Newbie

Joined: 02 Mar 2002 Posts: 34 Location: Union, CT USA
|
Posted: Sat Apr 24, 2010 12:05 am Post subject: Final (?) post to this |
|
|
I finally had a chance to get back to this and work out what I believe is the solution - wanted to post it in case anyone else is trying to use this. The code below works fine getting AD Group Membership, including nested groups when run on XP.
It appears that the bug under Windows 7 (at least Pro and Enterprise (aka Ultimate)) is with DSGet.exe. If you replace the Windows 7 version of DSGet.exe with the XP version, but leave the Win7 versions of DSQuery.exe and DSQuery.dll the expand command works fine.
REM Create list to hold Groups
%%GroupList = @NEW(LIST)
REM Get AD Group membership for logged in user
RUNH CMD /C @WINDIR(S)\dsquery user -samid @ENV(USERNAME) | @WINDIR(S)\dsget user -memberof -expand,pipe
REM Pipe Groups into a list
List assign,%%GroupList,@pipe() _________________ Dave Heck
dheck1961@cox.net
Union, Connecticut USA |
|
| Back to top |
|
 |
|