[python-win32] ADSI and LDAP Searches

Gooch, John John.Gooch at echostar.com
Wed Jun 29 21:42:04 CEST 2005


Hey, I am converting a Perl script into a Python script, and the part where
the Perl script is searching Active Directory using the LDAP interface is
throwing me a curve ball.

Here is a search for a Windows Group in Perl:
my $hdb = Win32::OLE->new("ADODB.Connection");
$hdb->{Provider} = "ADsDSOObject";
$hdb->Open("ADSI Provider");  
$rs =
$hdb->Execute("<$adsdomain>;(&(objectCategory=Group)(name=$groupname));adspa
th;SubTree");


Here is what I have in Python so far:
    adsi = win32com.client.Dispatch('ADsNameSpaces')
    ldap = adsi.getobject('','LDAP:')
    DSO = ldap.OpenDSObject("","","", 0)

It errors on the DSO line. I am guessing that the 'DSO' Python object is the
equivalent of the Perl "$hdb" object, but I don't know the syntax. I could
be complete off-base here as the document I have found via Google don't
explain what the code is doing, so I am left guessing.


Any help would be appreciated.

Thank You, 

John A. Gooch
Systems Administrator
IT - Tools
EchoStar Satellite L.L.C.
9601 S. Meridian Blvd.
Englewood, CO  80112
Desk: 720-514-5708 



-----Original Message-----
From: python-win32-bounces at python.org
[mailto:python-win32-bounces at python.org] On Behalf Of Schollnick, Benjamin
Sent: Tuesday, June 21, 2005 11:33 AM
To: Thomas Heller; python-win32 at python.org
Subject: Re: [python-win32] LsaLookupNames2



> Problems like this can be solved with dependencywalker
> (google for it). The walker displays binary dependencies for images.

Thankfully dependency issues like this seem to be rare....

> Using it I found this: win32net.pyd from build 204 does *not*
> use the LsaLookupNames2 function in advapi32.dll.  However, 
> win32net.pyd links to netapi32.dll (among others), and 
> netapi32.dll links to advapi32.dll, using the name 
> LsaLookupNames2.  This was on WinXP.
> 
> On win2k, netapi32.dll will not link to advapi32's
> LsaLookupNames2 - otherwise it would not work.
> 
> So, your exe *should* be able to run on win2k - except if you
> distribute XP's netapi32.dll with your exe (I've checked this 
> with a trivial py2exe'd script).

I just checked...  And guess what... Py2exe is bundling netapi32.dll... I am
working on a new beta, so I'll test to see if it will work on XP without
netapi32.dll being bundled...  If so, then we should be 
kosher...

Good catch...  I'll have to grab dependencywalker 
to get some practice...

> py2exe isn't very  good at determining which dlls belong to
> the operating system, and so must not be distributed - 
> netapi32.dll is such a beast.  You should remove netapi32.dll 
> from the dist directory, and it should work on win2k.

That's what I suspect....

> And sorry for the false alarm on the threads you mention above ;-)

It's okay....  I just miss McMillian's installer...
It's unsupported, so I've moved to py2exe...  But 
McMillian's package seemed to be better with
the dependency issues....  And offered a few
features that don't exist in py2exe... (Or at least
are not easily handled in py2exe...)

On the plus side, py2exe has handled packages lately
that I just could not get McMillian's installer
to work reliably with...  Which is why I switched...

Oh well... Progress...

		- Benjamin
_______________________________________________
Python-win32 mailing list
Python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32


More information about the Python-win32 mailing list