2004-04-05 18:05:14
先引入类型库(Project|Import Type Library)adsiis.dll、iisext.dll和activeds.tlb,新建一个单元,声明:
unit ActiveDs;
interface
function ADsGetObject(const PathName: WideString; const GUID: TGUID; out I: IUnknown): HRESULT; stdcall;
implementation
function ADsGetObject; external ’activeds.dll’ name ’ADsGetObject’;
end.
procedure TForm1.btn2Click(Sender: TObject);
var
I: IADsContainer;
ADs: IADs;
begin
if ADsGetObject('IIS://localhost/w3svc', IID_IADsContainer, IUnknown(I)) = S_Ok then
begin
ADs := IADs(I.GetObject('IIsWebServer', '1'));
if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then
begin
ADs := IADs(I.GetObject('IIsWebVirtualDir', 'Root'));
if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then
begin
ADs := IADs(I.Create('IIsWebVirtualDir', 'DelphiTest'));
ADs.Put('AccessRead', 'True');
ADs.Put('Path', 'F:\My Documents\Indy9Demos_26Oct04\Indy9Demos\HTTPServer\web');
ADs.SetInfo;
end;
end;
end;
end;
procedure TForm1.btn3Click(Sender: TObject);
var
Disp: IDispatch;
begin
Disp := IISNamespace.GetObject('IIsWebService', 'localhost/w3svc');
Disp := (Disp as IADsContainer).GetObject('IIsWebServer', '1');
Disp := (Disp as IADsContainer).GetObject('IIsWebVirtualDir', 'Root');
Disp := (Disp as IADsContainer).Create('IIsWebVirtualDir', 'DelphiADSITest');
(Disp as IADs).Put('AccessRead', 'True');
(Disp as IADs).Put('Path', 'c:ADSITest');
(Disp as IADs).SetInfo;