Re: MS VC++ 2003 and ADSI IID_IDirectorySearch

From: Joe Kaplan \(MVP - ADSI\) (joseph.e.kaplan_at_removethis.accenture.com)
Date: 03/30/04


Date: Tue, 30 Mar 2004 09:24:47 -0600

Do you know the name of the computer? Generally, you are going to write an
LDAP search filter for this that would go something like:

(sAMAccoutName=xxxx)

Where xxxx is the name of the computer you are looking for. sAMAccountName
is unique on the domain for all objects and is indexed, so this will find
the computer in any container and will be fast.

You also need to specify a root for your search which will probably be the
defaultNamingContext of the domain. You can get this dynamically by binding
to RootDSE with IADs and getting the defaultNamingContext attribute.

If you don't know the computer name, tell us what you do know.

I also highly recommend using MS's ldp.exe tool for modeling LDAP searches
against AD. It comes with the server support tools or the ADAM install.

HTH,

Joe K.

"Sten Westerback" <sten.westerback@NO_SPAMnokia.com> wrote in message
news:w0fac.12751$k4.264092@news1.nokia.com...
>
> Thanks, that was the key information i needed.
>
> Now i would only need to know which LDAP (i noticed that
> IDirectorySearch doesn't support "WinNT:") query to use to
> find a PC under "Workstations" container/folder and also how
> to get the full folder name ("Workstations\Country\Area").
> The reference only seems to discuss User related queries so help
> would be appreciated.
>
> - Sten
>
> "lev" <ltsentsiper@brandsoft.com> wrote in message
> news:miaac.131648$1p.1773045@attbi_s54...
> > Simply insert in one of yours cpp files the following line:
> >
> > extern const IID IID_IDirectorySearch=__uuidof(IDirectorySearch);
> >
> >
> > "Sten Westerback" <sten.westerback@NO_SPAMnokia.com> wrote in message
> > news:fST9c.12655$k4.261802@news1.nokia.com...
> > > Hi
> > >
> > > Can anyone help me understand why i get and how to fix the following
> > > MS VC++ 2003 error message
> > > ReadAD.obj : error LNK2001: unresolved external symbol
> > > _IID_IDirectorySearch
> > > while trying to compile...
> > > CoInitialize(NULL);
> > > if (ADsOpenObject(L"WinNT://NOE/Workstations", p_szU, p_szP,
> > > ADS_READONLY_SERVER, IID_IDirectorySearch, (void **) &p_DS)!=S_OK)
> > return
> > > FALSE;
> > >
> > > i=sprintf((char *) szQuery, "(Computer=%s)", p_szPCname);
> > > MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR) szQuery, i+1,
> > wszQuery,
> > > sizeof(wszQuery)/sizeof(wszQuery[0]));
> > > if (S_OK != (p_DS->ExecuteSearch(wszQuery, (LPWSTR *) L"ADsPath", 1,
> > > &hADS)))
> > > { CoUninitialize(); return FALSE; }
> > > // ... other lines here
> > > return TRUE;
> > >
> > > What puzzles me is that the IID_IDirectorySearch is declared
> > > as extern in two headers both of which i have included.
> > >
> > > ADSIid.h
> > > extern const GUID IID_IDirectorySearch;
> > >
> > > Iads.h
> > > EXTERN_C const IID IID_IDirectorySearch;
> > >
> > > But obviously that variable isn't defined anywhere such as the
> > > ActiveDS.lib that i have included in the project. So where is it?
> > >
> > > The .cpp module is part of a native style Win32 GUI application
> > > which also contains .c modules.
> > >
> > > Also, is this the proper method to get the fully qualified domain
> > > name ("path") of a computer object in Active Directory or how
> > > would one do that?
> > >
> > > Thanks,
> > > Sten
> > >
> > >
> > >
> >
> >
>
>