The 1C:Enterprise developers forum

#1
People who like this: 0 Yes / 0 No
Active user
Rating: 2
Joined: Aug 10, 2012
Company: N/A

Hi,

I need to connect to MS Exchange for getting the company accounts list.
With some languages such as VB Script, Java,.. and so on there is a way to do that with LDAP protocol.

Could you please give me a way to do that in 1C:Enterprise?
Or
Is there any way to connect MS Exchange from 1C:Enterprise?

NOTE: I am developing the managed application.


Thanks,
Cuong

 
#2
People who like this: 0 Yes / 0 No
Timofey Bugaevsky
Guest

Joined:
Company:

Hello, Nguyen Trung Cuong.

You can use COM object of Active Directory to manage users and for other tasks.

Code
Com = New COMObject("ADODB.Command");

More details you can find in Microsoft documentation.

 
#3
People who like this: 0 Yes / 0 No
Active user
Rating: 2
Joined: Aug 10, 2012
Company: N/A

Hello, Timofey Bugaevsky,

My code procedure seems not to work correctly (tested on local PC).
Could you show me where is wrong?

Code
&AtServer
Procedure LoginAD()
    strTarget = "LDAP://localhost/RootDSE";
    
    Connection     = New COMObject("ADODB.Connection");
    Connection.Provider = "ADsDSOObject";
    Connection.Open("Active Directory Provider");

    Command = New COMObject("ADODB.Command");
    Command.ActiveConnection = Connection;
    Command.CommandText = "SELECT Name, ADsPath FROM '" + strTarget + "' WHERE objectCategory = 'user'";
    Command.CommandType = 1;
           
    RecordSet = New COMObject("ADODB.RecordSet");
    RecordSet = Command.Execute();
    While Not RecordSet.EOF Do
         Message(RecordSet.Fields("Name").Value);         
         RecordSet.MoveNext();
    EndDo;
EndProcedure

Error messages is attached in this e-mail (error.png, error_detail.png)!

Thank you very much!
Cuong

Download error.png (13.38 KB)
 
#4
People who like this: 0 Yes / 0 No
Timofey Bugaevsky
Guest

Joined:
Company:

Hello,

Try to escape characters / \ , by using a back slash before them. In your case this might work:

Code
    strTarget = "LDAP:\/\/localhost\/RootDSE";

 
#5
People who like this: 0 Yes / 0 No
Active user
Rating: 2
Joined: Aug 10, 2012
Company: N/A

Hello,

Thank you for your support!

Unfortunately the program throws exception with the content that LDAP path is not correct.

I tried to input the correct company LDAP path but get the same exception although my LDAP path is correct because it's login successfully with Active Directory Explorer.

Could you suggest another way to connect Active Directory?

Thanks,
Cuong

 
#6
People who like this: 0 Yes / 0 No
Timofey Bugaevsky
Guest

Joined:
Company:

I'm afraid you are mixing SELECT and LDAP commands command text should appear like this:

Code
CommandText = "<LDAP://localhost..."

 
#7
People who like this: 0 Yes / 0 No
Active user
Rating: 2
Joined: Aug 10, 2012
Company: N/A

Hello,

I tried your solution and get the following exception message:
"..Error calling context method (Execute) RecordSet = Command.Execute(); because: An exception has occurred (Provider): Table does not exist."

Could you please try to run this code script in your 1C:Enterprise environment?

The updated code is below:

Code
&AtServer
Procedure LoginAD()
    
    strTarget = "<LDAP:\/\/localhost\/>";
    
   Connection     = New COMObject("ADODB.Connection");
    Connection.Provider = "ADsDSOObject";
    Connection.Open("Active Directory Provider");
   

    Command = New COMObject("ADODB.Command");
    Command.ActiveConnection = Connection;
    Command.CommandText = "SELECT Name, ADsPath FROM '" + strTarget + "' WHERE objectCategory = 'user'";
    Command.CommandType = 1;
           
    RecordSet = New COMObject("ADODB.RecordSet");
    RecordSet = Command.Execute();
    While Not RecordSet.EOF Do
         Message(RecordSet.Fields("Name").Value);         
         RecordSe t.MoveNext();
    EndDo;
EndProcedure

Thanks,
Cuong

Edited: Nguyen Trung Cuong - Dec 15, 2015 11:46 PM
 
#8
People who like this: 0 Yes / 0 No
Timofey Bugaevsky
Guest

Joined:
Company:

Hello, Nguyen Trung Cuong.

You need to change this string:

Code
    Command.CommandText = "SELECT Name, ADsPath FROM '" + strTarget + "' WHERE objectCategory = 'user'";

With something like that:
Code
    Command.CommandText = "<LDAP://dc=NA,dc=fabrikam,dc=com>;;name;subtree"

I'm not a big specialist in Active Directory, so I can only suggest you the idea.

 
Subscribe
Users browsing this topic (guests: 3, registered: 0, hidden: 0)