Desktop version

Main > Forum > 1C:Enterprise Platform > 1C:Enterprise – Business applications platform > Access MS Exchange from 1C:Enterprise via LDAP protocol

Forum

Search UsersRules
Access MS Exchange from 1C:Enterprise via LDAP protocol
#1
Active user
Points:: 0
Joined:: Aug 10, 2012

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

Profile
#2
Guest
Points::
Joined::

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.

Profile
#3
Active user
Points:: 0
Joined:: Aug 10, 2012

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

Profile
#4
Guest
Points::
Joined::

Hello,

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

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

Profile
#5
Active user
Points:: 0
Joined:: Aug 10, 2012

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

Profile
#6
Guest
Points::
Joined::

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

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

Profile
#7
Active user
Points:: 0
Joined:: Aug 10, 2012

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

Profile
#8
Guest
Points::
Joined::

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.

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



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.