I've been wanting to sort out my own stuff for a long time, but I haven't had the time, my skills are too low, and I'm afraid of wasting other people's time, so I haven't written anything yet. But every time I see other people's articles, I feel itchy, so I find a post I have published on www.delphibbs.com to give back to everyone.
{************************************************ ********************** }
{ }
{ }
{ zhao zhenhua }
{}
{ Copyright zhao zhenhua email:[email protected] }
{ }
{************************************************ ********************** }
unit MainUnt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, FileCtrl, Buttons,Activeds_TLB;
type
TIISConfigFrm = class(TForm)
edtAlias: TEdit;
Label1: TLabel;
dlbIIS: TDirectoryListBox;
dcbIIS: TDriveComboBox;
Label2: TLabel;
edtPath: TEdit;
GroupBox1: TGroupBox;
cbRead: TCheckBox;
cbScript: TCheckBox;
cbExecute: TCheckBox;
cbWrite: TCheckBox;
cbBrowse: TCheckBox;
bbtOK: TBitBtn;
lblPath:TLabel;
PRocedure dlbIISChange(Sender: TObject);
procedure bbtOKClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{Private declarations}
public
{Public declarations}
end;
function ADsGetObject(const PathName: WideString; const GUID:TGUID; out I: IUnknown): HRESULT; stdcall;
var
IISConfigFrm: TIISConfigFrm;
implementation
{$R *.dfm}
function ADsGetObject;external 'ActiveDS.dll' name 'ADsGetObject';
procedure TIISConfigFrm.dlbIISChange(Sender: TObject);
begin
edtPath.Text:=dlbIIS.Directory;
end;
procedure TIISConfigFrm.bbtOKClick(Sender: TObject);
var
I: IADsContainer;
ADs: IADs;
begin
if Length(Trim(edtAlias.Text))=0 then begin
application.MessageBox('Alias cannot be empty!','Warning');
Exit;
end;
if Length(Trim(edtPath.Text))=0 then begin
Application.MessageBox('Please select the virtual directory location!','Warning');
Exit;
end;
if ADsGetObject('IIS://localhost', IID_IADsContainer, IUnknown(I)) = S_Ok then begin //IIS has been installed
if ADsGetObject('IIS://localhost/w3svc', IID_IADsContainer, IUnknown(I)) = S_Ok then begin //Web server exists
ADs := IADs(I.GetObject('IIsWebServer', '1')); //Get services
if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then begin //Service support
ADs := IADs(I.GetObject('IIsWebVirtualDir', 'Root')); //Create a virtual directory under the Root of the Web server
if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then begin //Service support
try
ADs := IADs(I.Create('IIsWebVirtualDir', edtAlias.Text)); //Create a virtual directory with an alias of edtAlias.Text
except
Application.MessageBox('This alias already exists, please choose another alias!', 'Warning');
Exit;
end; //try except
ADs.Put('accessRead', cbRead.Checked); //Set each parameter
ADs.Put('AccessWrite', cbWrite.Checked);
ADs.put('AccessScript',cbScript.Checked);
ADs.Put('AccessExecute',cbExecute.Checked);
ADs.put('EnableDirBrowsing',cbBrowse.Checked);
ADs.Put('Path', edtPath.text);
ADs.Put('DefaultDoc','Default.asp, Default.html, Default.htm, index.asp, Index.html, Index.htm, Home.asp, Home.Html, Home.htm');
ADs.Put('EnableDefaultDoc',True);//Allow default files to be opened
ADs.SetInfo; //Save parameters
Application.MessageBox('Your settings have been saved.','Congratulations');
end;
end;
end;
end else
Application.MessageBox('IIS is not installed on your computer or you do not have permission to access IIS.', 'Warning');
end;
procedure TIISConfigFrm.FormCreate(Sender: TObject);
begin
edtPath.Text:=dlbIIS.Directory;
end;
end.