Solved

Delphi and ADSI

Posted on 2002-03-07
2
1,952 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 79
Best Firemonkey component pack 1 101
How to define IfThen functions in one common unit? 4 50
Multi-layered image in FireMonkey 9 31
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

786 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