ADO authentication example (Perl)

This code can be found in Chapter 1 of Windows Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# Adapted from VBScript code contained in the book:
#      "Windows Server Cookbook" by Robbie Allen
# ISBN: 0-596-00633-0

use Win32::OLE;
$Win32::OLE::Warn = 3;

$strBaseDN = '<LDAP://dc=rallencorp,dc=com>;';
$strFilter = '(&(objectclass=computer)(objectcategory=computer));';
$strAttrs = 'cn;';
$strScope = 'subtree';
$objConn = Win32::OLE->new('ADODB.Connection');
$objConn->{Provider} = 'ADsDSOObject';
$objConn->SetProperty("Properties", 'User ID', 'administrator@rallencorp.com');
$objConn->SetProperty("Properties", 'Password', 'net');
$objConn->Open('Active Directory Provider');
$objRS = $objConn->Execute($strBaseDN . $strFilter . $strAttrs . $strScope);
$objRS->MoveFirst();
while (!$objRS->EOF) {
    print $objRS->Fields(0)->Value, "\n";
    $objRS->MoveNext();
}

This code has been viewed 1601 times.

New from the creators of TechTasks.com: StatSheet.com