Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




VBA LDAP Problem


I have written some VBA code that uses LDAP to request user's name and memberof property for either win2000/Xp and office2000/xp machines.
This all works fine whilst I have administrator rights but when tested on a clients machine I can not use the memberof function to work due to a error 13 type mismatch. This only occurs if not an administrator!?! Below is the code i'm using.

Does anyone know why I would get this when only as a non adminitrator or if it is a security issue how to get around it??

Many thanks.

On Error GoTo eh

Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)

txtusrfull = LCase(Join(CurrentUser.memberof))




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Ldap With Nt4
I have a script to make a user is Active Directory but how does this works in windows nt4 with the ldap???????
CREATE USER

Set objOU = GetObject("LDAP://OU=management,dc=fabrikam,dc=com")

Set objUser = objOU.Create("User", "cn=MyerKen")
objUser.Put "sAMAccountName", "myerken"
objUser.SetInfo

Ldap
Anyone know where I can find code to interface with LDAP?

I eventually need to make a DLL that I can pass a username and password and get everything that LDAP knows about that user. We have a package here in java that does it, but I dont know enough about java to convert it.

Cheers.

\Mike

LDAP
Hi,

I need to write a program that extracts data from an LDAP database. I have no experience with LDAP. Can anyone point me in the right direction - articles, code snippets, web sites etc... so I can make a start.

So far I have started reading some of the stuff in MSDN - but the fog isn't clearing.

Thanks

Ldap
Can anyone tell me how to use LDAP in VB? I would like to authenticate a user through Exchange which I hear that I can do using LDAP. Does anyone have an example or a site I can see one at?

Ldap
I need some samples of how to query an LDAP server without the ASDI control. Maybe the winsock control?

Ldap
hi,

does anyone have a sample code of a program that connects to the ldap
setting?



macky

LDAP
hi, good day to all of you...

i have a problem regarding the LDAP concept.
is there a way for me how to connect to the LDAP using VB6.0?
how can i can the fields?
can someone show me what the LDAP connection string looks
like for VB6.0?

your help and assistance will be a great help...thanks a lot guys.

VB - LDAP
How to get started with LDAP in VB? I know LDAP, dont know how to use in VB...

I tried an example in another post:

Dim obj As IADs
Dim cls As IADsClass
Dim pList As IADsPropertyList
Set obj = GetObject("LDAP://LDAPSERVER/dn")

Dim xa As Variant

xa = obj.Schema

I get this error: "User Defined Type not Defined" (On the first Line of code: "Dim obj As IADs"

This may be a dumb question, but I could use help on this...THANKS!!!!

Help: What Is 'LDAP'?
I recently downloaded a code from the internet. A part of its code says:

Code:
Set oRoot = GetObject("LDAP://rootDSE")
sDomain = oRoot.Get("defaultNamingContext")

'Set oDomain = GetObject("LDAP://" & sDomain)



This part of the code triggers and says 'The specified domain does not exist or clould not be contacted'.


Is there a certain procedure I should do first in order for this program to run properly?
What is LDAP?
Is this already web programming?



Please somebody help me...

LDAP In VB
Hi All,

I have a login screen in which user is required to enter username and password. What i need to do is to authenticate the UserName with the LDAP server in VB. once the user is found as valid user, i need to check this user name against a department Number ? How do i do this.

Dim openDS As IADsOpenDSObject
Dim objContainer As IADsContainer

Set openDS = GetObject("LDAP:")
Set objContainer = openDS.OpenDSObject("LDAP://xyz.com:38010", _
"uid=" & txtUserName.Text & ",ou=People, o=fedex, c=us", txtPassword.Text, 0)
if above code gives the error, then the user is not valid. This is working already.

How do i pass DepartmentNumber in the above code and validate the user against it ?

Do you have any idea on that ? Pls help me. It's urgent.

Thanks,
Josh

Ldap
Does anyone know, how to authenticate user name and password using LDAP in VB ? I am very new to this LDAP.

Please help me.

Thanks!

Authentication With LDAP
This isn't the same thing everyone else has been asking about...

A quick summery of what I'm doing:
I wrote a form & bas file that I can use with any other application that i develope for our company. If your logged in, in the local network, it will get your username, find out what ou your in, and if your in the proper ou it will let you use the software. Great. heres the hard part.

If you use this program from outside our network. It will see that your not logged in, prompt you for a valid login (which it does, and works). IF your login is sucessful, then it goes to find out what ou your in to validate your permissions to use that program. Thats where im having the problem. Sure, i can check to see if you have a valid username & password. But how do i actually log you in, or apply that login to the following code?


Code:
Set objObject = GetObject("LDAP://secure.ecschem.com:389/CN=Administrator,OU=HQ,OU=Users,OU=ECS Accounts,DC=ecschem,DC=com")
Thats the line its actually hanging up on. Saying automation error.

Now, before anyone jumps to conclusions. Remember I said i am already verifying the username & pw before i get to this step. So my communication with LDAP is working, and this code works PERFECT when you use it locally. (when your logged into the workstation).

PLEASE PLEASE help. I could really use the advice.

LDAP (ADSI)
Dear All,

Has anyone managed to succesfully query ldap server or exchage server with VB. I have tried using code on microsoft site i get the following error

table does not exist

Thanks in advance

LDAP Quering ?
My tree is something like as shown below:

DC=Ch,DC=com
OU=Uni,DC=Ch,DC=com
OU=Nod,OU=Uni,DC=Ch,DC=com
CN=1,OU=Nod,OU=Uni,DC=Ch,DC=com
OU=De,CN=1,OU=Nod,OU=Uni,DC=Ch,DC=com

I want all under CN=1 and all under OU=De ?
How do i do that,could you help me with some code,coz i tried ur code and maybe i am not specifying right.

Thanks
Balaji

Ldap Wmi Winnt
I use this to get all the users of a doman:

Code:
Dim adGroup As ActiveDs.IADsGroup
Set adGroup = GetObject("WinNT://" & cstrDomain & "/" & cstrGroup & ",group")

Can someone tell me what is LDAP used for beside adding new users to a domain? Can it do the samething as the above? From my research, LDAP is the true object that controls Active Directory right? The code above that I listed is only for queueing the domain right?

I got this from somewhere which I can't remember where. I need help on the following to make it work:


Code:
Dim sysInfo As ADSystemInfo
Dim oUser As ActiveDs.IADsUser
Dim LName As String, FName As String
Set sysInfo = CreateObject("ADSystemInfo")
Set oUser = GetObject("LDAP://CN=" & theLastName & "," & theFirstName & ",OU=Users,OU=myCurrentDivision,DC=myCompany,DC=com ")
Debug.Print oUser.EmailAddress
Set sysInfo = Nothing
Set oUser = Nothing
I am having problems understanding and filling in all the OU and DC.

Thank You

LDAP - Possible Attributes?
I'm using this code below to return info for all LDAP users. However, I'm pretty sure that there are more attributes than the ones specified in this line:
strAttributes = "name,distinguishedName,cn,givenName,sn,emailaddress"

But where can I find a list of all possible attributes?


VB Code:
Public Sub GetUsers()Dim oConnection As ADODB.ConnectionDim oCmd As ADODB.CommandDim oRecordSet As ADODB.RecordsetDim oField As ADODB.FieldDim oRootDSE As IADsDim strNamingContext As StringDim strADOQuery As StringDim strAttributes As StringDim strFilter As String ' --- Define the attributes to be returned from the query ---strAttributes = "name,distinguishedName,cn,givenName,sn,emailaddress" ' --- Get a filter from the user ---strFilter = Trim(InputBox("Please input a filter to find users. Entering nothing will return all users." + vbLf + vbLf + "Example : (sn=Smith) finds all users with the last name Smith", "Enter a filter"))  '--- Get the Naming Context ----Set oRootDSE = GetObject("LDAP://RootDSE")strNamingContext = oRootDSE.Get("defaultNamingContext")Set oRootDSE = Nothing  '--- Set up the connection ---Set oConnection = New ADODB.ConnectionSet oCmd = New ADODB.CommandoConnection.Provider = "ADsDSOObject"oConnection.Open "ADs Provider"Set oCmd.ActiveConnection = oConnection '--- Build the query string ---strADOQuery = "<LDAP://" + strNamingContext + ">;(&(objectCategory=person)(objectClass=user)" + strFilter + ");" + strAttributes + ";subtree"oCmd.CommandText = strADOQueryoCmd.Properties("Page Size") = 1000'--- Execute the query for the user in the directory ---Set oRecordSet = oCmd.Execute While Not oRecordSet.EOFFor Each oField In oRecordSet.Fields'Output each field and value to the debug windowDebug.Print oField.Name + " : " + oField.ValueNextoRecordSet.MoveNextDebug.Print 'Prints blank lineWend ' -- Clean up --oRecordSet.CloseoConnection.CloseSet oField = NothingSet oRecordSet = NothingSet oCmd = NothingSet oConnection = NothingEnd Sub

Query LDAP Using ADO
I have an application that takes an LDAP search string including the uid and then returns the common name as a string. It works fine, but unfortunately after about 3500 uses in a loop it starts to fail with "Table does not exist" (as in the connection details are incorrect) for a while and then it recovers and starts working again. The loop goes something like this:


VB Code:
' Set up the ADODB.Connection object and call the .Open methodoLDAP.Connect  While not EOF  ' GetCN uses oRecordSet = oConnection.Execute("SELECT cn FROM.... ")  ' to either return the cn string or return "*NULL TRACE*" and report reason  ' to the debug window  sSomething = oLDAP.GetCN("uid=blah,o=glah,ou=etc,dc=etc")Wend oLDAP.Disconnect ' closes the ADODB.Connection  


I can't understand why it works inconsistently as the connection details do not change, however Ethereal (packet sniffer) shows that the connection is opened and closed on each iteration, where I would have thought that the connection would stay open until specifically closed (i.e. outside the loop). So I figure I'm either using ADO incorrectly or I'm hammering the LDAP connection pool until it runs out (LDAP connection is remote).

I would be grateful for any clues?

LDAP Query
Can anyone give me some hints on how to query LDAP with an email address? I am trying to figure out th OU for users and the only consistent piece of information from my data set is their email address.

My problem is in my bind string.

This works:
LDAP://DC=myDomain;(&(objectclass=user) (cn=Doe_John))

With that bind string I can retrieve the user object and get John's email address. But I have his email address and want his cn.

This does not work:
LDAP://DC=myDomain;(&(objectclass=user) (email=JohnD@myDomain.com))

Any suggesstions would be appreciated.

ADSI And LDAP
Hello,

I am creatingt an app to do some user maintenance in Active Directory. What I am trying to do is attain container names depending on the context information provided by the user.

For example, a user will select which administration they work for and tell me the division of that administration, this will give me enough information to know the context of the user, but I want to display the child containers of there context. Does this make sense?

Thanks

LDAP Command
Code:
objCommand.CommandText = "<LDAP://dc=domain,dc=net>;(&(objectCategory=person)(objectClass=user)(name=" & strUserName & "*" & "));name,distinguishedname, givenName,sn;subtree"


Say I want to get more then just "name,distinguishedname, givenName,sn" out of my query. is there a * that will retrive all information about this users record.

ADSI And LDAP
Here's my code:

Public Sub CreateExchangeAccount(strFirstName, strLastName, strUserName, strDomain As String)

On Error GoTo ErrorCreatingExchangeAccount

Dim objCont As IADsContainer
Dim objMailbox As IADsUser
Dim sec As New ADsSecurity
Dim sd As SecurityDescriptor
Dim ace As New AccessControlEntry
Dim dacl As AccessControlList
Dim sid As New ADsSID

Const ADS_SID_HEXSTRING = 1
Const ADS_SID_WINNT_PATH = 5
Const ADS_RIGHT_EXCH_MODIFY_USER_ATT = &H2
Const ADS_RIGHT_EXCH_MAIL_SEND_AS = &H8
Const ADS_RIGHT_EXCH_MAIL_RECEIVE_AS = &H10

strMTA = "cn=Microsoft MTA,cn=PCNET,cn=Servers,cn=Configuration,ou=PCNET,o=Pikeville College"
strMDB = "cn=Microsoft Private MDB,cn=TITAN,cn=Servers,cn=Configuration,ou=PCNET,o=Pikeville College"
strRecipCont = "LDAP://TITAN:389/cn=Recipients,OU=PCNET,O=Pikeville College"
strDisplayName = strFirstName & " " & strLastName
strSMTPAddr = strUserName & "@pc.edu"
strX400Addr = "c=US;a= ;p=Pikeville Colleg;o=PCNET;s=" & strUserName

'---------------------------------------------------------------

Set objCont = GetObject(strRecipCont)
Set objMailbox = objCont.Create("organizationalPerson", "cn=" & strUserName)

objMailbox.Put "mailPreferenceOption", 0
objMailbox.Put "givenName", strFirstName
objMailbox.Put "sn", strLastName
objMailbox.Put "cn", strDisplayName
objMailbox.Put "uid", strUserName
objMailbox.Put "Home-MTA", strMTA
objMailbox.Put "Home-MDB", strMDB
objMailbox.Put "mail", strSMTPAddr
objMailbox.Put "textencodedORaddress", strX400Addr
objMailbox.Put "MAPI-Recipient", True
objMailbox.Put "rfc822Mailbox", strSMTPAddr

'--We've kinda created the mailbox - now we need to associate the account _
with the account... Give them permission to read/send, etc...


sid.SetAs ADS_SID_WINNT_PATH, "WinNT://" & strDomain & "/" & strUserName & ",user"
sidHex = sid.GetAs(ADS_SID_HEXSTRING)
objMailbox.Put "Assoc-NT-Account", sidHex

'--------Ownership set - now create.

objMailbox.SetInfo


'--------We now need to bestow the correct permissions to the user.

Set sd = sec.GetSecurityDescriptor(objMailbox.ADsPath)
Set dacl = sd.DiscretionaryAcl

ace.Trustee = strDomain & "" & strUserName
ace.AccessMask = ADS_RIGHT_EXCH_MODIFY_USER_ATT Or _
ADS_RIGHT_EXCH_MAIL_SEND_AS
ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED

dacl.AddAce ace
sd.DiscretionaryAcl = dacl

'************************************************
sec.SetSecurityDescriptor sd

'--The last line is the one we are having trouble with...
' We are not able to ACTUALLY tie in the account with the mailbox.
'************************************************

Exit Sub

ErrorCreatingExchangeAccount:
MsgBox "Error creating account for user: " & OurUserName & vbCrLf & _
"We acquired an Error Message of " & Err.Description, vbCritical, "Error Creating NT Account"

NoErrorCreatingExchangeAccount:

End Sub

-----------------------------------------------
The account is created and bound to an NT account but permissions for this account are not being set up properly. I think that it has to do with the AccessControlEntry, AccessControlList and SecurityDescriptor. I can't seem to find a DLL with the actual IADsSecurityDescriptor - if anyone could help me out here I would be forever indebted to you... You can see where the Error exists - just slightly above this message.

Thanks,

Robbie A. Scott

Writing To LDAP With VB6
I've got an application that reads LDAP perfectly using the ADs Provider object. What I would like to do now is write modified values back to the LDAP server. The application runs on multiple workstations throughout the organization and the LDAP server is a SuSE box running LDAP services. I would like to be able to write back to the LDAP using the same ADsProvider, however, I'm desperate at this point, anything will work. I've tried using ADSI with Microsoft with no success.
Any help would be great. Thanks.

Mark

Using VB For Ldap Authentication
I am writting a secured application in VB with a SQL Server Backend and I
must do a secondary password authentication to LDAP. Does any one know a method for doing this?

LDAP Filter
I'm trying to use an LDAP Filter to access the record of a workstation where the isdusers attribute contains the users ID.

the filter I have at the moment looks like:
sFilter = "(&(objectCategory=Computer)(objectClass=computer)(isdusers=6021134))"

The attribute value is
CN=6021134,OU=End Users,OU=Accounts,DC=userdomain01,DC=domroot,DC=internal

I've tried the filter with the full value and just the CN. Can't see where I'm going wrong. Everybody is somebodys Nutter.

LDAP - List All OUs
Hey guys

How can you fill an arry with all OUs (only first level - the rest has to be no problems)?

Question On LDAP
I was trying to autheticate users using LDAP.
Actually, i have developed the VB6.0 application on
Windows 2000. It's works very fine. But in Windows NT
machines, it is not working. I really donno why ? I have installed ADSI 2.5 on this Windows NT machine and tried but the effort was in vain. It's giving error at line # 8 in below code i.e while executing the LDAP SQL.

Can anyone pls help ? It would be of great help for me. I
thank you all a lot in advance.

If you want to look at the code, it is below:
---------------------------------------------------
Dim openDS As IADsOpenDSObject
Dim objContainer As IADsContainer
Dim Rs As New ADODB.Recordset
Dim oConnection As New ADODB.Connection
Dim oCommand As ADODB.Command
Dim strLine As Integer


On Error GoTo err_para

' Check whether user exists in the LDAP server
strLine = 1
Set openDS = GetObject("LDAP:")
strLine = 2
Set objContainer =
openDS.OpenDSObject("LDAP://pnrapp.prod.fedex.com:38010",
_

"uid=446971,ou=People, o=fedex, c=us", fedex123, 0)

strLine = 3
Set oConnection = CreateObject("ADODB.Connection")
strLine = 4
Set oCommand = CreateObject("ADODB.Command")

' Open the connection.
oConnection.Provider = "ADsDSOObject" ' This is
the ADSI OLE-DB provider name
strLine = 5
oConnection.Open "Active Directory Provider"


' Create a command object for this connection.
strLine = 6
Set oCommand.ActiveConnection = oConnection

' Compose a search string.
strLine = 7
oCommand.CommandText = "SELECT departmentnumber
FROM 'LDAP://pnrapp.prod.fedex.com:38010/ou=People,
o=fedex, c=us' " & _
"WHERE uid='446971' AND
(departmentnumber='301434*' OR
departmentnumber='300815*' OR " & _

"departmentnumber='30042*')"

' Execute the query.
strLine = 8
Set Rs = oCommand.Execute

' Check whether user exists in the department
codes '301434*' or '300815*' or '30042*'
strLine = 9
If Rs.RecordCount = 0 Then
intCount = intCount + 1
MsgBox "This is a valid user but does not
exists in following Department Codes: " & Chr(13) &
Chr(13) & " '301434*' " & Chr(13) & " '300815*' " &
Chr(13) & " '30042*'", vbExclamation, "SPAT-Interim"
If intCount = 3 Then End
Exit Sub
End If

MsgBox "LDAP worked!!!"

Exit Sub



err_para:

MsgBox "Line: " & strLine & " Error: " & Err.Description
---------------------------------------------------

Querying In LDAP ?
My tree is something like as shown below:

DC=Ch,DC=com
OU=Uni,DC=Ch,DC=com
OU=Nod,OU=Uni,DC=Ch,DC=com
CN=1,OU=Nod,OU=Uni,DC=Ch,DC=com
OU=De,CN=1,OU=Nod,OU=Uni,DC=Ch,DC=com

I want all under CN=1 and all under OU=De ?
How do i do that,could you help me with some code,coz i tried ur code and maybe i am not specifying right.

Thanks
Balaji

Accessing LDAP From Vb6
Hello,

I would like to know how to access LDAP read and write to it from vb6.0
Please send some code samples.

Thanks,
Balaji

LDAP Search
I need to obtain the OU that a User is in without searching every OU. I want to create an LDAP search string that will find that user name even if the user is buried in an OU and I can't seem to be able to get it to work. Any ideas out there?

CodeHacker
Rate me if it helped, Thanks

LDAP With Active Directory
I'm using the code below to run a very simple report.
The code works fine.

What's wrong is that I am only seeing a portion of our users.
I know that the 'missing' users are in a Win2k3 domain, in an OU called "Department", then drill down to several OU's called "Users".
(ie <Department - DEPT1 - Users> and <Department - DEPT2 - Users>)
But I can't seem to get there from here...


Code:
Dim cnUser As IADsContainer
Dim adUser As IADsUser

Dim strFilePath As String
Dim intFileNum As Integer

strFilePath = "c:ldaptest.txt"

Set cnUser = GetObject("LDAP://cn=users,dc=int,DC=fakeDCname,DC=local")
cnUser.Filter = Array("User")

intFileNum = FreeFile
Open strFilePath For Output As #intFileNum

For Each adUser In cnUser
Print #intFileNum, adUser.samaccountName, adUser.extensionattribute1
Next

Close #intFileNum

Remote LDAP Query
Is it possiable to connect to a LDAP directory of a remote domain on the same network? I am domain XYZ, there is a domain ABC which I am not apart of but I can remote desktop to, how can I write a connection string to connect?

LDAP Authentication On Win98?
Is there a way to get LDAP Authentication to work on a Win98 Client?

LDAP Objects (CNs) With Commas
I can run a script to reset passwords for users with a simple common name after an inputbox assigns to a strLastName, strFirstName that eventually resolve to strNewLDAPName.

Account Name: libstudent1, testuser, remote, etc.
Display/Common Name: libstudent1, testuser, remote, etc. (cn=libstudent1)

The line of code that assigns the CN to the objUser looks like this.


Code:
Set objUser = GetObject("LDAP://cn="& strNewLDAPName & ",ou=" & strContainer)

But here’s the actual question. How do I get the GetObject code to retrieve a common name that has a comma and a space in it?

Account Name: hanz.magoo
Display/Common Name: Magoo, Hanz (so the cn=Magoo, Hanz).

It should be noted that I’ve made a script to reset Hanz's account manually. “Manually” meaning I declare the objUser in the script like this, with no inputboxes:


Code:
Set objUser = GetObject("LDAP://cn=Magoo, Hanz,ou=High School,dc=student,dc=bridgecityisd,dc=com")

Following that logic, I would assume it would go something like this, but it does not, and gives me an invalid dn syntax error:


Code:
Set objUser = GetObject("LDAP://cn="& strLastName & "," & strFirstName & ",ou=" & strContainer)

Needless to say, I'm confused.

The links below are resources that I've used that give some insight on the problem. After looking at them, is there a way to “trick” the GetObject into reading a string like he does in the link’s example?

http://www.microsoft.com/technet/scr...4/hey1105.mspx

From what I understand, the backslash is required to tell the LDAP that there’s more CN information following the strLastName.

http://msdn2.microsoft.com/en-us/library/aa366101.aspx

LDAP VB6 Object Model
I need to access LDAP servers using visual basic 6. I was wondering if there was an LDAP class/library or and LDAP object model that was documented somewhere. I looked around the Microsoft Knowledge Base and MSDN but couldn't find anything. Thanks for your help.

LDAP Group Search
HI!

I'm working for an entreprise with a amazing Active Directory with many O.U. So, I want to know if is possible to "getObject" without the path...

like: (WinNt:\domainGroup)

If not what is the best code to search many O.U.

Remember the AD contains more then 500 O.U, more than 10 000 group...

Ldap - Searching AD Database?
im trying to get a list of all users in our domain who can revieve external email. there are quite a few of us, so im trying to find a way to search active directory using ldap, or even better would be to use the filter built into AD.

the hitch is i dont know how to preform queries, though i know the property im looking for is:

msExchRequireAuthToSendTo

i need to enumerate each ou and user and then check to see what the value of this is so i can determine who has what.

any links or ideas would be xtremely helpful.
thanks for your time.

LDAP Authentication On Win98?
Is there a way to get LDAP Authentication to work on a Win98 Client?

LDAP Objects (CNs) With Commas
I can run a script to reset passwords for users with a simple common name after an inputbox assigns to a strLastName, strFirstName that eventually resolve to strNewLDAPName.

Account Name: libstudent1, testuser, remote, etc.
Display/Common Name: libstudent1, testuser, remote, etc. (cn=libstudent1)

The line of code that assigns the CN to the objUser looks like this.


vb Code:
Set objUser = GetObject("LDAP://cn="& strNewLDAPName & ",ou=" & strContainer)


But here’s the actual question. How do I get the GetObject code to retrieve a common name that has a comma and a space in it?

Account Name: hanz.magoo
Display/Common Name: Magoo, Hanz (so the cn=Magoo, Hanz).

It should be noted that I’ve made a script to reset Hanz's account manually. “Manually” meaning I declare the objUser in the script like this, with no inputboxes:


vb Code:
Set objUser = GetObject("LDAP://cn=Magoo, Hanz,ou=High School,dc=student,dc=bridgecityisd,dc=com")


Following that logic, I would assume it would go something like this, but it does not, and gives me an invalid dn syntax error:


vb Code:
Set objUser = GetObject("LDAP://cn="& strLastName & "," & strFirstName & ",ou=" & strContainer)


Needless to say, I'm confused.

The links below are resources that I've used that give some insight on the problem. After looking at them, is there a way to “trick” the GetObject into reading a string like he does in the link’s example?

http://www.microsoft.com/technet/scr...4/hey1105.mspx

From what I understand, the backslash is required to tell the LDAP that there’s more CN information following the strLastName.

http://msdn2.microsoft.com/en-us/library/aa366101.aspx

Connecting To LDAP Server From Vb 6.0 App
hi all,

I wanna connect to an Active Directory from my Vb 6.0.
Can anyone of you please provide some guidance on how to proceed with it.
A piece of sample code will be very helpful.

Thanks inadvance,
Veena

Ldap Query And Subschema
I am new with ldap and VB so please don't flame me to bad

I am trying to create an app that will query our ldap and return the data back to a series of text boxes to be used for other applications later on. I can do basic queries against like the cn and the pager but our company has a subschemaSubentry and most of the information I need comes from that. Anytime I add an attribute from that list, I get an unspecified error in VB. My code is listed below.

I changed some aspects in the server names and the o= to hide the innocent

VB Code:
Option ExplicitDim conn As ADODB.ConnectionDim rs As ADODB.RecordsetDim strname As StringDim I As Variant Private Sub Form_Load() Set conn = New ADODB.Connectionconn.Provider = "ADSDSOObject"conn.Open "ADs Provider" Set rs = conn.Execute( _"<LDAP://SERVER:389/uid=username,ou=Employees,o=****>;" _& "(objectClass=*);departmentnumber;subtree") While Not rs.EOF    If IsArray(rs.Fields(0)) Then        For i = LBound(rs.Fields(0).Value) To UBound(rs.Fields(0).Value)            If rs.Fields(0).Value(i) <> "" Then                txtName.Text = rs.Fields(0)(i)            End If        Next    Else        MsgBox rs.Fields(1)    End Ifrs.MoveNext Wend conn.Close End Sub




dj







Edit: Added [vbcode][/vbcode] tags for more clarity. - Hack

Help Please, I Am Rubbish : LDAP Query
Hi, I am completely new to vb scripting and do not know muck at all. I ungently need to write a vb script that queries LDAP for all SMTP addresses out of AD that end in a specific way i.e.. ABC.com This needs to be for all users (including multiple email addresses), Custom contacts and distribution groups. I would also like to write the output info into a text file. but only the smtp addresses. This list will then be used to feed into out mail sweeper, but that is not needed from the script only the list is needed. Can anyone help me or point me in the right direction. Huge thanks in advance. David Kent

LDAP Connection Setup
I am trying to create a VB6 program to run on a stand alone Windows XP workstation to enumerate all of the users in an Active Directory. Is there a way to get the organization structure of a directory if you only know the domain name?

Most of the examples I have seen you arr are connecting to some kind of server, i.e.
Code:
Set objContainer = openDS.OpenDSObject("LDAP://xyz.com:38010", _
"uid=" & txtUserName.Text & ",ou=People, o=MyOrg, c=us", txtPassword.Text, 0)
Our company domain is called companynet, so I tried the following:
Code:
Set objContainer = openDS.OpenDSObject("LDAP://companynet", _
"uid=" & txtUserName.Text & ",ou=People, o=MyOrg, c=us", txtPassword.Text, 0)
but it does not find the server. I get the error "The server is not operational". Is there a way to find the server for the AD?

Am I going about making this connection the right way?

Thanks Steve

LDAP Connection && Search ???
Hello All,

I am having trouble with making an Ldap connection.

I need to be able to Connect to an Ldap server & Check a users, Username & Password !!

Fairly simple or so i thought, but i have now tried out a number of different examples on the Web & and am still having trouble !!

at the moment i am using the following code to connect to the ldap server & attempt to query it !


VB Code:
Dim com As ADODB.CommandDim con As ADODB.ConnectionDim strServername As StringDim dn As StringDim sn As StringDim strSearchBase As StringDim password As StringDim rs As ADODB.RecordsetDim strQuery As String (NB I HAVE HAD TO REMOVE OUR IP ADDRESS,CN & PASSWORD INFO)  strServername = "IP"strSearchBase = "IP/"dn = "cn=CN,o=O"sn = "thomson"password = "PASSWORD" 'Initialize variablesSet con = CreateObject("ADODB.Connection")con.Provider = "ADsDSOObject" 'Bind to the Directory Servercon.Open strServername, dn, passwordSet com = CreateObject("ADODB.Command")com.ActiveConnection = con  strQuery = "<LDAP://" & strSearchBase & ">;(&(telephoneNumber=*)(sn=" & sn & "));cn,telephoneNumber,ou;subtree" com.CommandText = strQuerycom.Properties("Page Size") = 99   'a paged query is used to avoid Exchange LDAP server limitsSet rs = com.Execute   'Execute the query  


This seems to work (the connection code seems to work) apart from the fact that the ldap server i am trying to connect to is not Active Directory, and when i tried to Search the ldap, i got an ERROR that an

- "Ivalid Active Directory Pathname was passed"

I am assuming that this is to do with the Provider name i have given !!!, but wouldn't know what to change it to ???

HELP please, or point me to some clearly explained Examples!

Thanks in advance

-Richard

LDAP And ADSI Authentication...
Not sure if this should be in general or API, so here goes...

I need to authenticate users for a VB6 app running on Win2000 that I'm working on. They need to: 1) be authenticated when logging into the app (i.e., they login with username and password which is their normal windows password using NT authentication); 2) Be authenticated when they perform a database write for an "electronic signature" (also using the same NT authentication).

I've heard some stirrings that LDAP and ADSI could accomplish this, but I'm not finding any information on this anywhere (including the internet). So far I can find and return a user's full name given their userID with the following code (which requires a reference to Active DS Objects):


Private Sub cmdFullName_Click()
If Me.txtUserName.Text = "" Then
MsgBox "Enter a username already!!!"
Exit Sub
End If

Dim User As IADsUser
Dim UserName As String
Dim UserDomain As String
UserDomain = "<domain>"
UserName = Me.txtUserName.Text
Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user")

Dim RetVal As String, strFirst As String, strLast As String
RetVal = User.FullName
Me.txtFullName = User.FullName
'Debug.Print RetVal

End Sub


It shouldn't be much of a stretch from this to writing a function that looks on the domain controller and returns true if the userID and password validates and false otherwise. I've dug through an entire 500 page book on ADSI for NT/2000 Administrators and have found nothing pertaining to Authentication (though I learned a lot of other useful & cool stuff).

Anyone ever done this or know anyone who has?

Thank you!

Ed

ADSI And LDAP Programming
Can I Add a new Paramter fot he Domain USer

I mean If I want a new parameter such as The Extension Number or the mobile Number so that It can be retrieved later as another parameter such as User Password or Group ????

Dial-In Properties With LDAP
I have been struggling over this all day and I'm about to throw my computer out the window. I am trying to create a script to modify the User Dial-In properties, which has to be done with LDAP. I can modify it to "True" or "False" without a problem... but of course the one I need to set it to "EMPTY" (aka: Control Access Through Remote Access Policy) does not work. Every Microsoft TechNet, MSDN and example I have found says to do it this way:

UsrObj.Put "msNPAllowDialin", EMPTY

When I do that I get:
Error: Unspecified Error
Code: 80004005
Source: (null)

I've tried everything, and nothing seems to work. Has anyone done this successfully?

My Code:

Code:


Set UsrObj = GetObject("LDAP://CN=Schmoe Joe, OU=Users,DC=Microshaft,DC=COM")

wscript.echo UsrObj.msNPAllowDialin & vbcrlf

' Set RAS Option
UsrObj.Put "msNPAllowDialin", EMPTY
'Apply RAS Option
UsrObj.SetInfo
'echo to check changes
wscript.echo UsrObj.msNPAllowDialin & vbcrlf

Authenticate To LDAP From Workgroup
Hi Everyone,

To fill you in on the background.....

I have recently assembled a script for new PC builds that after sysprep will name the machine, join it to the domain to a specified OU and now I would like to add the machine to some software GPO's.

The machine is set to logon as the local administrator for each of these stages and so far all bar the last are working without fault.

My problem is that the local administrator has no right to AD therefore the script will not work, is there a way to logon to AD within the script to make it work?. I do have a domain account available to do this as it is used to name the machine and join the domain.

So far I have got the script working on a domain computer running with my admin account. If it helps, the strDNSDomain would be "DC=ad,DC=ICanNotTellYou,DC=gov,DC=uk".

The relevant part of the script is as follows :-


Code:

'Capture Local Machine Name
Set objNetwork = CreateObject("Wscript.Network")
strComputerName = "CN=" & ucase((objnetwork.computername))

'Capture AD Root Domain Information
Set objRootLDAP = GetObject("LDAP://RootDSE")
strDNSDomain = objRootLDAP.Get("DefaultNamingContext")

'Add Machine Object to GPO Object
strGPOName = "CN=SW - Adobe Acrobat Reader 8.0.0 (XP)"
strGPOLocation = "OU=Unlicensed,OU=_Generic Software,OU=Software Distribution"
strOUName = "ou=Computers_Imaged"

Set objGroup = GetObject ("LDAP://" &strGPOName& "," &strGPOLocation& "," &StrDNSDomain)
Set ocomputer = GetObject ("LDAP://" &strComputerName& "," &strOUName& "," &strDNSDomain)
objGroup.add ocomputer.adspath



Thank you in advance for reading this and hopefully somebody will be able to help.

John

Get LDAP User Info *Need Help*
I have been trying for like a week on how to get the user info from LDAP. I'm in Access using VBA with ADO as my connection. I really want to get the lastaccesstime for each user in a container folder.

My code is as follows:

Code:


Public Function FirstScript(strFilePath As String)
Dim con As ADODB.Connection
Dim cmd As ADODB.command
Dim rs As ADODB.Recordset
Dim txtMsg As String
Dim ADsPath As String

ADsPath = "LDAP://directorydev.domain.com/aid=it0030,ou=Applications,o=domain.com,c=us"

'set the connection
Set con = New ADODB.Connection
With con
.Provider = "ADsDSOObject"
'.Properties("ADSI Flag") = 0
.Open "ADSI", , 0
End With

'set the command object
Set cmd = New ADODB.command
With cmd
.ActiveConnection = con
.CommandText = "<" & ADsPath & ">;(&(userreferencedn=*xternal*)(auid=pp123));ADsPath;Subtree"
.Properties("Page Size") = 1000
.Properties("Timeout") = 30
.Properties("Cache Results") = True
End With

Set rs = cmd.Execute 'run the query and get records
If Not (rs.BOF And rs.EOF) Then 'while BOF and EOF means no files rs.MoveLast 'waits until last record is loaded and then points there rs.MoveFirst 'moves to the first records
Debug.Print "Record Count: " & rs.RecordCount

While Not rs.EOF 'prints out record until there are no more (end of file) Debug.Print rs.Fields(0)
rs.MoveNext
Wend


'||||||||||||||||||||||||||||||||||||||||||||||
' This section is only here for testing
On Error Resume Next
Dim propList As IADsPropertyList
Dim propEntry As IADsPropertyEntry
Dim propVal As IADsPropertyValue 'As IADsProperty
Dim propval2 As IADsPropertyValue2
Dim propCount As Long
Dim i As Integer, v

rs.MoveFirst
Set propList = GetObject(rs.Fields(0).Value)
propList.GetInfo
propCount = propList.PropertyCount
Debug.Print vbTab & "No. of Property Found: " & propCount

For i = 0 To propCount - 1
Set propEntry = propList.Item(i) 'Each item in property list has a property entry
txtMsg = txtMsg & vbTab & propEntry.Name & vbTab

For Each v In propEntry.Values
Set propVal = v
txtMsg = txtMsg & propVal.ADsType & vbTab 'Append to outputstring.
Next
txtMsg = txtMsg & vbNewLine
Next
'||||||||||||||||||||||||||||||||||||||||||

Debug.Print txtMsg
End If

'close and clean up
rs.Close
Set rs = Nothing
cmd.Cancel
Set cmd = Nothing
con.Close
Set con = Nothing
End Function



The output is:

Code:

Record Count: 1
LDAP://directorydev.domain.com/auid=pp123, aid=it0030, ou=Applications, o=domain.com, c=US
No. of Property Found: 6
accesscounter 11
lastaccesstime 11
userreferencedn 11
objectclass 3 3
role 11
auid 11


I get an <Application-defined or object-defined error> for all other objects of the PropertyValue object, except for the ADsType. However, when the ADsType was 3 (the objecclass) the CaseIgnoreString object of PropertyValue was populated.


Thank you anybody who can help

LDAP Query Problem
Hi

I am trying to do a authentication of username and password fro Excel application with LDAP server as most of our users ar having userid configured to LDAP server. I am trying to quer the LDAP server(iPLANET) through VB(ADSI) to get the usernam and facing connection issues.



Here is the Code :



Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim Command



Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADsDSOObject"

conn.Open "ADs Provider"

Set com = CreateObject("ADODB.Command")
com.ActiveConnection = conn

com.CommandText =3 "<LDAP://kuwait.ccs.com/OU=9000,OU=Associa tes,DC=dir,DC=ccs,DC=et>; (uid=" & uid & ");cn;subtree"

Set rs = com.Execute



I am getting "Table does not exits" error at Set rs = com.Execut line .



My LDAP server name is kuwait.ccs.com

My Dn is dc=dir,dc=ccs,dc=net

The uid is =19990001

This uid is inside OU = Associates->9000.



Should I give the DC values as DC=kuwait,DC=ccs,DC=net or the wa I gave is right? I have also tried changing the sequence o OU=Associates first and OU=9000 next in the query line,but stil I have problem.

Also when I see the log created in the LDAP server is like thi :



[19/Jan/2006:16:54:03 -0500] conn=90971 op=-1 msgId=-1 - fd=3 slot=37 LDAP connection from 172.24.37.97 to 166.86.124.73

[19/Jan/2006:16:54:03 -0500] conn=90971 op=0 msgId=268 - SRC base="" scope=0 filter="(objectClass=*) attrs="subschemaSubentry dsservicename namingContext defaultnamingcontext schemanamingcontex configurationnamingcontext rootdomainnamingcontex supportedControl supportedLDAPVersion supportedldappolicie supportedSASLMechanisms dnshostname ldapservicename servernam supportedcapabilities"

[19/Jan/2006:16:54:03 -0500] conn=90971 op=0 msgId=268 - RESUL err=0 tag=101 nentries=1 etime=0

[19/Jan/2006:16:54:03 -0500] conn=90971 op=1 msgId=270 - BIN dn="" method=sasl version=3 mech=GSSAPI

[19/Jan/2006:16:54:03 -0500] conn=90971 op=1 msgId=270 - RESUL err=14 tag=97 nentries=0 etime=0, SASL bind in progress

[19/Jan/2006:16:54:03 -0500] conn=90971 op=2 msgId=271 - BIN dn="" method=sasl version=3 mech=GSSAPI

[19/Jan/2006:16:54:03 -0500] conn=90971 op=2 msgId=271 - RESUL err=49 tag=97 nentries=0 etime=0

[19/Jan/2006:16:54:03 -0500] conn=90971 op=3 msgId=272 - BIN dn="" method=128 version=3

[19/Jan/2006:16:54:03 -0500] conn=90971 op=3 msgId=272 - RESUL err=0 tag=97 nentries=0 etime=0 dn=""

[19/Jan/2006:16:54:03 -0500] conn=90971 op=4 msgId=273 - SRC base="ou=9000,ou=associates,dc=dir,dc=ccs ,dc=net" scope= filter="(objectClass=*)" attrs="objectClass"

[19/Jan/2006:16:54:03 -0500] conn=90971 op=4 msgId=273 - RESUL err=0 tag=101 nentries=0 etime=0

[19/Jan/2006:16:54:03 -0500] conn=90971 op=5 msgId=274 - UNBIND

[19/Jan/2006:16:54:03 -0500] conn=90971 op=5 msgId=-1 - closing U1

[19/Jan/2006:16:54:04 -0500] conn=90971 op=-1 msgId=-1 - closed.



It seems to be the method of communication is SASL where as thi service is not configured in the LDAP server. Is this the reaso it is failing? I have gone through the tips from most of th forums and tried all the possibilites but still I am facing thi error.



Please help me. Thanks for the help in advance.

Vivek

Copyright © 2005-08 www.BigResource.com, All rights reserved