Look for Stuart Dunkeld <sp> and vfp and wmi. He has some libraries that
will do this for you and also some adsi code. Craig Boyd also has some
sample code, and I think I put some somewhere....

John

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf
Of Jarvis, Matthew
Sent: Thursday, June 23, 2011 1:33 PM
To: [email protected]
Subject: Code: is username in AD group?

Came up with some code yesterday for something that had been stumping me for
a couple weeks and finally came back to it late in the afternoon...

 

If you want to check if a username is in any particular group within a
domain, here is the code that seems to do it. This is in MS Access VBA but
should be easy to translate. Thought others might find it useful...

 

Generically speaking, you need three pieces of info for this:

 

Domain: US

Group: MWMC IT Department

Username: mjarvis

 

------------------------------------------------------------

Set GroupObj = GetObject("WinNT://us/MWMC IT Department")

 

foundFlag = False

 

For Each UserObj In GroupObj.Members

    'WScript.Echo UserObj.Name

  If (UCase(Trim("mjarvis")) = UCase(Trim(UserObj.Name))) Then

    MsgBox "Found: " & UserObj.Name

    foundFlag = True

  End If

Next

 

If foundFlag Then

    MsgBox "found"

Else

    MsgBox "not found"

End If

------------------------------------------------------------

 

 

 

Thanks,

 

Matthew Jarvis || Business Systems Analyst IT Department McKenzie-Willamette
Medical Center
1460 G Street, Springfield, OR  97477 || Ph: 541-744-6092 || Fax:
541-744-6145

 



--------------------------------------------------------------------------
Disclaimer: This electronic message may contain information that is
Proprietary, Confidential, or legally privileged or protected. It is
intended only for the use of the individual(s) and entity named in the
message. If you are not an intended recipient of this message, please notify
the sender immediately and delete the material from your computer. Do not
deliver, distribute or copy this message and do not disclose its contents or
take any action in reliance on the information it contains.

--- StripMime Report -- processed MIME parts --- multipart/alternative
  text/plain (text body -- kept)
  text/html
---

[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to