C++/VB - Newbie - Help tiding code !!

Asked By Jez
27-Jan-10 12:56 PM
The vbs code below does as I would expect, but I think there must be a
better way of doing the for each loops.
Can any one help / advise !
Thanks

' Instantiate the connection and log in to OpenLDAP
Set oConn = CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOObject"
oConn.Open "ADs Provider", "USERNAME", "PASSWORD"

' Build the LDAP search condition...
vSearch = "(cn=*)"


' Execute the search...
Set oRS = oConn.Execute("<LDAP://10.10.10.1:389/cn=Devices>;" &
vSearch & ";cn,guid,id")

' Create an array of returned values
vCount = 0
While not oRS.EOF

For Each vCN in oRS.Fields("cn").value
For Each vID in oRS.Fields("id").value
For Each vGUID in oRS.Fields("guid").value

WScript.Echo vCN & " = " & vID & " - " & vGUID

Next
Next
Next

vCount = vCount + 1
oRS.MoveNext
Wend
ADODB.Connection
(1)
Active Directory
(1)
ADsDSOObject
(1)
OpenLDAP
(1)
ADODB
(1)
SAMAccountName
(1)
OctetToHexStr
(1)
ObjectGUID
(1)
  Richard Mueller [MVP] replied to Jez
27-Jan-10 08:46 AM
The loop should be similar to:
==========
While not oRS.EOF

vCN = oRS.Fields("cn").value
vID = oRS.Fields("id").value
vGUID = oRS.Fields("guid").value

WScript.Echo vCN & " = " & vID & " - " & vGUID

vCount = vCount + 1
oRS.MoveNext
Wend
=======
However, there are no "id" or "guid" attributes. You may want the
sAMAccountName attribute, which is the "pre-Windows 2000 logon" name of
users (and computers and groups). This is sometimes called the userID of
users. GUID is a property method, not an attribute, and cannot be retrieved
using ADO. You can retrieve the objectGUID attribute instead, but this is a
byte array, so you need a function to convert it into a string. For example
the following function:
===========
Function OctetToHexStr(ByVal arrbytOctet)
' Function to convert OctetString (byte array) to Hex string.
Dim k

OctetToHexStr = ""
For k = 1 To Lenb(arrbytOctet)
OctetToHexStr = OctetToHexStr _
& Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
Next
End Function
=========
Finally, your LDAP filter, "(cn=*)" will return just about all objects in
Active Directory. If you want to only retrieve user objects use the filter:

(&(objectCategory=person)(objectClass=user))

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
  Jez replied to Richard Mueller [MVP]
27-Jan-10 07:54 PM
On 27 Jan, 13:46, "Richard Mueller [MVP]" <rlmueller-
ed
a
le
2)
in
r:

Hi Richard
Many thanks for your reply.
Create New Account
help
code below : USER DOES'NT EXIST But the user exsits, I can see it with Active Directory and the sAMAccountName is good ? '- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - Const adPosEOF = -3 Set objConnection = Wscript.CreateObject("ADODB.Connection") Call objConnection.Open ("Provider = ADsDSOObject;") Set objCommand = Wscript.CreateObject("ADODB.Command") objCommand.ActiveConnection = objConnection objCommand.CommandText = "<LDAP: / / DC = yourcenar, DC = local" _ & "> ;(ObjectCategory = user);sAMAccountName Echo "USER DOES'NT EXIST" End If Call objRecord.Close() Call objConnection.Close() '- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - VBScript Discussions ADODB.Connection (1) ADODB.Command (1) Active Directory (1) Windows Server (1) Page (1) ADODB (1) Hopefully
for select * from person; end LM; VB6 looks like this. . . Dim con As New ADODB.Connection Dim cmd As New ADODB.Command Dim rst As New ADODB.Recordset With con .CommandTimeout = 10 .ConnectionString = "" .Provider = "MSDAORA" .Open "Provider = OraOLEDB.Oracle; Data Source = * ** ** *; User cmd .Parameters.Refresh .ActiveConnection = con .CommandType = adCmdStoredProc .CommandText = "LOGMNR.LM" End With Set cmd = New ADODB.Command cmd.Parameters.Add cmd.CreateParameter("p_filename", adVarChar, adParamInput, 255, FullTargetPath) 'cmd.Parameters.Append cmd return a recordset from Oracle to VB6? Thanks in advance. Dave VB DataBase ADO Discussions ADODB.Connection (1) ADODB.Command (1) OraOLEDB.Oracle (1) ADODB.Recordset (1) Oracle (1) ADODB (1) Debug.Print (1
guru needed -> problem connecting to .dbf using ADODB C++ / VB , problem, connecting, to, .dbf, using, ADODB" / > Hi, I been looking for answers for this problem and have not been very lucky. I am trying to connect to a .dbf file from VB6 (Free table directory, for the sample below I have a dbfFileName.dbf file inside the folder App.Path As String: sFolder = App.Path & " \ databases" Dim sTable_ As String: sTable_ = "dbfFileName" Dim cnn As ADODB.Connection: Set cnn = New ADODB.Connection Dim rst As ADODB.Recordset: Set rst = New ADODB.Recordset cnn.Provider = "VFPOLEDB.1" cnn.Properties("Data Source") = sFolder
OLEDB.4.0;Data Source = \ DC02 \ GPC_DB \ GPCData.mdb;User Id = admin;Password = ; Error Message: ADODB.Connection: Provider cannot be found. It may not be properly installed. Office 2007, including Access, is I would think any required components should be present. What am I missing? VBScript Discussions ADODB.Connection (1) ADODB.Recordset (1) Office 2007 (1) Access 2007 (1) Office 2003 (1) Windows 7 (1) ADODB (1) XP (1) Access 2007 uses a new OLEDB driver, Microsoft.ACE.OLEDB.12.0 _ & "Data Source = c: \ MyFolder \ MyDatabase.mdb;" _ & "Persist Security Info = False;" - - Richard Mueller MVP Directory Services Hilltop Lab - http: / / www.rlmueller.net - - Sorry, no fix yet. . . Good to know about Persist Security Info = False" WScript.Echo "Connection string:" & _ vbCrLf & _ strConnection Set objConnection = CreateObject("ADODB.Connection") 'Errors occur here, when they happen. . . objConnection.Open strConnection WScript.Echo "!!Connection succeeded!!" Set
have succeeded to create mysql database. I did the following code : Try ConnStr = conn = New ADODB.Connection() conn.ConnectionString = ConnStr conn.Open() Catch MsgBox("#" & Err.Number & ", " & Err.Description) End Try I got driver specified. What may be the reason for the above ? Thanks :) VB DataBase ADO Discussions ADODB.Connection (1) MySQL (1) VB.NET (1) ADODB (1) VB (1) MyFirstDB (1) Database (1) DataSource (1) Try changing "localhost" to the name problems, try all other possibilities found here: http: / / connectionstrings.com / mysql HTH Hey What is ADODB.Connection in your code? - Is this a ODBC driver or the .NET driver? Localhost is correct there you want have installed an ODBC driver which has the name you told the ADODB. I think you use VB.NET? - If so, do not use ODBC, use .NET Connector