Solved

Delphi and ADSI

Posted on 2002-03-07
2
1,908 Views
Last Modified: 2007-11-27
is there any pas files that define the ADSI interfaces/objects/functions that I can use with Delphi to access Active Directory.
0
Comment
Question by:mem100
2 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6849505
hi,
can you import the typelib activeds.tlb to get some functions.

there is an article on "Searching in ADSI from Delphi" in The
Delphi Magazine, Issue No. 62 - Oct 2000. with component TADSISearch to do exactly that. Comes with sample code.

You can download the code from the Delphi magazine's web site:
http://tdmwebx.com/dmdisks/dmag62.zip

and you can order the back issue from their web site:

http://www.thedelphimagazine.com/conts/conts62.php
and article using adsi in back issue 76:
http://www.thedelphimagazine.com/conts/conts76.php



also i saved below form a paq that may be useful for you:

>>>>>>start paste:

These are not perfect, but do a fair bit of useful stuff
----------
interface

function ADsGetObject(lpszPathName: PWideChar; const riid: TIID;   out obj): HResult; stdcall;
function hhGetObject(Id:PWideChar):variant;
function hhGetTopServerId(const w3svc:variant):integer;
function hhMakeWebServer(const w3svc:variant;
                         const IPAddress:string='';
                         const IPPort:integer=80;
                         const Description:string='New Web Site'):variant;
function hhMakeVirtualDirectory(const webserver:variant;
                                const Path:string; //**
                                const HomeDirectory:string; //**
                                const DefaultDocument:string='default.htm'; //**
                                const EnableDefaultDocument:boolean=TRUE;
                                const ReadPermission:boolean=FALSE;
                                const WritePermission:boolean=FALSE;
                                const DirectoryBRowsing:boolean=FALSE;
                                const ExecutePermission:boolean=FALSE):variant;

implementation

function ADsGetObject;  external 'activeds.dll';
function hhGetObject(Id:PWideChar):variant;
begin
  if ADsGetObject(Id, IDispatch, TVarData(result).VDispatch) = S_OK then
    TVarData(result).vType := varDispatch
  else
    Result:= Unassigned;
end;

function hhGetTopServerId(const w3svc:variant):integer;
var
  I:integer;
  ws:variant;
begin
  if not varisempty(w3svc) then
  begin
    Result:=-1;
    i:=0;
    repeat
      try
        inc(i);
        ws:=w3svc.GetObject('IIsWebServer', i);
      except on e:exception do
        Result:=i-1;
      end;
    until Result<>-1;
  end
  else
    Result:=-1;
end;

function hhMakeWebServer(const w3svc:variant;
                         const IPAddress:string='';
                         const IPPort:integer=80;
                         const Description:string='New Web Site'):variant;
var
  NewId:integer;
begin
  if not VarIsEmpty(w3svc) then
  begin
    NewId:=hhGetTopServerId(w3svc)+1;
    result:=w3svc.Create('IIsWebServer',NewId);
    result.ServerComment:=Description;
    result.ServerBindings:=VarArrayOf([IPADdress+':'+inttostr(IPPort)+':']);
    result.Keytype:='IIsWebServer';
    result.setinfo;
  end
  else
    result := Unassigned;
end;

function hhMakeVirtualDirectory(const webserver:variant;
                                const Path:string; //**
                                const HomeDirectory:string; //**
                                const DefaultDocument:string='default.htm'; //**
                                const EnableDefaultDocument:boolean=TRUE;
                                const ReadPermission:boolean=FALSE;
                                const WritePermission:boolean=FALSE;
                                const DirectoryBRowsing:boolean=FALSE;
                                const ExecutePermission:boolean=FALSE):variant;
begin
  if not VarIsEmpty(WebServer) then
  begin
    Result:=WebServer.Create('IIsWebVirtualDir',Path);
    Result.Path := HomeDirectory;
    Result.DefaultDoc := DefaultDocument;
    Result.EnableDefaultDoc := EnableDefaultDocument;
    Result.EnableDirBrowsing := DirectoryBrowsing;
    Result.AccessExecute := ExecutePermission;
    Result.AccessRead := ReadPermission;
    Result.AccessWrite := WritePermission;
    Result.AccessSource := FALSE;
    Result.SetInfo;
  end
  else
    Result:=UnAssigned;
end;



-- EXAMPLE CALLS --
var
  w3svc,WebServer,RootDir,ScriptDir:variant;
begin
  w3svc:=hhGetObject('IIS://LocalHost/W3SVC');
  if not VarIsEmpty(w3svc) then
  begin
    WebServer:=hhMakeWebServer(w3svc,'192.168.10.1',80,'Web Web Site');
    RootDir:=hhMakeVirtualDirectory(WebServer,'ROOT','C:\INETPUB\WWW','index.html',TRUE,TRUE,FALSE,FALSE,FALSE);
    ScriptDir:=hhMakeVirtualDirectory(RootDir,'Scripts','C:\INETPUB\IMAGES','',FALSE,FALSE,FALSE,FALSE,TRUE);
    WebServer.Start;
  end
  else
    ShowMEssage('Failed');
end;



-- USEFUL URL --

MSDN Documentation on IIS ADSI ..
http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/psdk/iisref/adsi57hv.htm


with thanks to crazner
0
 

Author Comment

by:mem100
ID: 6850168
thanks I also found the following to be used if you're interested

http://www.agnisoft.com/adsi/adsicode.zip
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now