The following is a subroutine I wrote for querying AD for OU path
information on a user account. Hope it helps.
use Win32::OLE;
use Win32::OLE::Const;
my $name = "Microsoft ActiveX Data Objects 2\\.0 Library";
$ado_consts = Win32::OLE::Const->Load($name)
|| die "Unable to load Win32::OLE::Const ``$name'' ".Win32::OLE->LastError;
sub SearchAD
{
($Account) = @_;
undef $AdsPath;
$Root = Win32::OLE->GetObject("LDAP://RootDSE");
$DefaultDomainNC = $Root->Get("DefaultNamingContext");
undef $Root;
if ("" eq $DefaultDomainNC)
{
Win32::MsgBox("Error. Did not get the Default Naming
Context",
MB_ICONSTOP , "Source User Error");
return;
}
$ADOConn = Win32::OLE->new("ADODB.Connection");
$ADOConn->{Provider} = ("ADsDSOObject");
$ADOConn->{ConnectionString} = ($DefaultDomainNC);
$ADOConn->Open("Active Directory Provider");
$ADOCommand = Win32::OLE->new("ADODB.Command");
$ADOCommand->{ActiveConnection} = $ADOConn;
$ADSQuery = "SELECT AdsPath FROM \'LDAP://$DefaultDomainNC\' WHERE
samAccountName = \'$Account\'";
$ADOCommand->{CommandText} = $ADSQuery;
$ResultSet = Win32::OLE->new("ADODB.Recordset");
$ResultSet = $ADOConn->Execute($ADSQuery);
$AdsPath = $ResultSet->Fields(0)->{Value};
$ResultSet->Close;
$ADOConn->Close;
return($AdsPath);
}
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 12, 2003 11:51 AM
To: [EMAIL PROTECTED];
[EMAIL PROTECTED]
Subject: ADODB ADSI OLE DB connection open problems
Hi All,
I am having trouble connecting anonymously to Active Diretory through an
ADODB
connection using OLE. I can run the connection but can't open it. Here is a
code snippet:
# environment variables
use Win32::OLE; # base functionality
use Win32::OLE::Variant; # support for OLE data types
use Win32::OLE::Const ('Active DS'); # load ADSI constants
use Win32::OLE::Const ('Active X Data Objects');# load ADO constants
# AD OLE DB Search variables and connection
my $iADDBStateOpen = 1;
if (my $oADConnection = Win32::OLE->CreateObject("ADODB.Connection")
) {
$Response->Write("ADODB Connection made ");
$oADConnection->{Provider} = "ADsDSOObject";
if ($oADConnection->open()) {
$Response->Write("Open Connection successful ");
}
else {
my $error = Win32::OLE->LastError();
$Response->Write("Open Connection failed. Error:
$error ");
}
}
else {
$Response->Write("ADODB Connection failed ");
}
I get 'ADODB Connection made Open connection failed. Error: 0'. When I run
the
same script converted to the command prompt it has a problem with the Const
line for the ADO constants, I comment this out and it gives me
authentication
failed.
I have also tried the 'Listing 6' code from
http://www.winnetmag.com/WindowsScripting/Article/ArticleID/5456/5456.html
and
it gives me authentication failed as well.
Thanks in advance for any help,
martin
--
Martin Douglas
[EMAIL PROTECTED]
ITS Network Programmer
661-2111 x.81187
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs