NameTranslate for an AD Group

Author Message
swlymer

  • Total Posts : 7
  • Scores: 0
  • Reward points : 0
  • Joined: 4/5/2005
  • Location:
  • Status: offline
NameTranslate for an AD Group Monday, May 16, 2005 5:29 PM (permalink)
0
Hi, I have the following script which pulss a Canonical Name for a security group from a databse. I am trying to use adsNameTranslate to translate the groups CN to it's distinguished name so I can add a user to that group programmatically. Here is the code I am working with. The script does not error when debugging so I believe the script is having difficulty when it gets to this point in the script.

' Get the DN of the group
strGroupDN = adsNameTranslate.Get(ADS_NAME_TYPE_1779)

Your help is greatly appreciated.

************************************************************************************

Option Explicit

Dim rsGrp, strGroup, strGroupDN, strUser, bDebug
Dim strUsr, adsDomain, sGrp, sDomain, adsGroup, strUserDN, strNTGRPDN
Dim sSQL, conSam, sConSam, adsNameTranslate, strNTGRPName

'*******************************************************************************
' Build Database connection strings
'*******************************************************************************
Set conSam = CreateObject("ADODB.Connection")
sConSam = "Provider=SQLOLEDB.1;Password=samadmin;Persist Security Info=True;User ID=samadmin;Initial Catalog=SAM;Data Source=STLAPP1\SAINT"

'*******************************************************************************
' Open Database connections
'*******************************************************************************
conSam.Open sConSam

If bDebug = False Then
On Error Resume Next
End If

Set rsGrp = CreateObject("ADODB.Recordset")

sSQL = "SELECT * FROM vwAddToSoiGrp"
rsGrp.Open sSQL, conSam
strGroup = ""
UpdateStatus "Adding Users to SOI group(s)"
Do While Not rsGrp.EOF

Set strGroup = rsGrp("Name")
Set strUser = rsGrp("Unique_Identifier")

' Constants for the NameTranslate object.

Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

' Specify the NetBIOS name of the domain and the NT name of the user.
'strNTGRPName = " & strGroup & "

' Use NameTranslate to look up the group in the directory
Set adsNameTranslate = CreateObject("NameTranslate")

' Specify the GC for quick lookups
adsNameTranslate.Init ADS_NAME_INITTYPE_GC, vbNull

' Set the group name into NameTranslate
' Specify unknown format to have object determine
adsNameTranslate.Set ADS_NAME_TYPE_UNKNOWN, strGroup

' Get the DN of the group
strGroupDN = adsNameTranslate.Get(ADS_NAME_TYPE_1779)

' Bind to group object
Set adsGroup = GetObject("LDAP://" & strGroupDN)

' Set the user name into NameTranslate
adsNameTranslate.Set ADS_NAME_TYPE_UNKNOWN, strUser

' Get the DN of the user
strUserDN = adsNameTranslate.Get(ADS_NAME_TYPE_1779)

' Bind to the user object
Set adsUser = GetObject("LDAP://" & strUserDN)

' Add user to group
adsGroup.Add adsUser.ADsPath

rsGrp.MoveNext
Loop
rsGrp.Close
 
#1

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2012 ASPPlayground.NET Forum Version 3.9