strat has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I've searched perlmonks and google and MSDN, but haven't found a solution for my problem. It looks very similar to Problems with Win32::OLE and ADSI

I try to connect to a Win2003 Active Directory running on a specific server from remote and log on as a certain user. The client is WinXP and a member of a subdomain, and the connect works well with adsi-browsers or pure ldap browsers or Net::LDAP, ane even this way of ADSI:

my $conn = Win32::OLE->new("ADODB.Connection"); $conn->{Provider} = "ADsDSOObject"; $conn->Open("ADSI Provider");

works fine, but there I don't know how to specify a certain server/user/password.

But I've got the problem that I can't logon with perl and the following way of ADSI.

The Perl-code stripped down to the essentials looks about the following

#! /usr/bin/perl use warnings; use strict; use Win32; use Win32::OLE; use Win32::OLE::Variant; my $server = "10.6.5.4"; my $base = "DC=myCompany,DC=at"; my $user = "cn=Administrator,cn=Users,$base"; #my $user = "Administrator"; my $pass = 'abcdefg'; my $objNameSpace = Win32::OLE->GetObject("LDAP://$server/$base") or die "Error: can't create LDAP object: $!\n"; # until now, everything has been fine, but now... #my $connectString = "LDAP://$server/$base"; #my $connectString = "LDAP://$base"; #my $connectString = "LDAP://$server/"; my $connectString = "LDAP:///$base"; print "Connectstring: $connectString\n"; my $conn = $objNameSpace->OpenDSObject ($connectString, $user, $pass, 0x01); use Data::Dumper; print Dumper($conn); # conn is undef my $err = Win32::OLE->LastError(); die "Error in bind: $err\n" if $err;

It seems not to matter what I use in $connectString, I always get the following error message:

D:\StratSync>testADSI.pl Connectstring: LDAP://10.6.21.131/DC=mlhelab,DC=de $VAR1 = undef; Error in bind: Win32::OLE(0.1701) error 0x8002000e: "Unzulőssige Param +eteranzahl" in METHOD/PROPERTYGET "" D:\StratSync>

(not correct count of parameters in...)

Well, Activestate OLE-Browser and MSDN tell me:

Function OpenDSObject(lpszDNName As String, lpszUserName As String, lp +szPassword As String, lnReserved As Long) As Object

Well, I've got four parameters, and for lnReserved I used every single parameter from ADS_AUTHENTICATION_ENUM (even 0x200)

Have you got any idea what I'm doing wrong?

Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Replies are listed 'Best First'.
Re: ADSI -> 0x8002000e Error
by neniro (Priest) on Jun 14, 2005 at 10:39 UTC
    my $user   = "cn=Administrator,cn=Users,$base";

    Why is it cn=Users and not ou=Users? I never had anything to do with Active-Directory but AFAIR in other LDAPs i've seen this as OU.

      cn=users is correct, because users is objectClass: container with naming attribute cn and not objectClass: organizationalUnit with naming attribute ou

      Best regards,
      perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

        Well, I've finally found the solution by myself

        use Win32::OLE; $Win32::OLE::Warn = 3; # see perldoc Win32::OLE my $userDn = 'cn=myself,ou=myOu,dc=myDomain,dc=myTld'; my $password = 'secret'; my @wantedFields = qw(ADsPath cn sn givenName sAMAccountName); my $searchFilter = "(&(objectClass=user)(sn=*))"; # connect to AD with user and password my $connObj = Win32::OLE->new('ADODB.Connection'); $connObj->{Provider} = 'ADsDSOObject'; $connObj->Properties->{'User ID' } = $userDn; $connObj->Properties->{'Password'} = $password; $connObj->Open('ADSI Provider'); # prepare a search my $searchString = join (";", "<LDAP://192.1.2.3/dc=myDomain,dc=myTld>", $searchFilter, join(",", @wantedFields), 'SubTree', ); my $adoCmdObj = Win32::OLE->new('ADODB.Command'); $adoCmdObj->{ActiveConnection} = $connObj; $adoCmdObj->{CommandText} = $searchString; $adoCmdObj->Properties->{'Page Size'} = 1000; # execute search and return user one by onesy my $rsObj = Win32::OLE->new('ADODB.RecordSet'); $rsObj->Open( { Source => $adoCmdObj } ); $rsObj->MoveFirst() if $rsObj and not $rs->EOF(); while (not $rsObj->EOF) { foreach my $i (0..$#wantedFields) { my $value = $rsObj->Fields($i)->{Value}; # $values may be a lot of different things that often # can't just be printed (e.g. octet string, multivalues) # Win32::OLE::Variant objects, ... # if you work with them, the following line doesn't make # much sense but has to be replaced printf "%s: %s\n", $wantedFields[$i], $value; } # foreach print "--------------\n"; # move "cursor" to next obj to prevent infinite loop $rsObj->MoveNext(); } # while $rsObj->Close(); $connObj->Close();

        Best regards,
        perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"