unit p_iis;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls, p_tabenter;
type
TFRM_IIS = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
EDCOMMENT: TEdit;
EDIPADDRESS: TEdit;
EDCOMMENTPATH: TEdit;
EDWEBNUM: TEdit;
Button1: TButton;
Button2: TButton;
cbstartiis: TCheckBox;
edport: TEdit;
Label5: TLabel;
kEnterAsTab1: TkEnterAsTab;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
function CheckInput: Boolean;
function ConfigWebServer: Boolean;
function ConfigWebVirtualCGIBIN: Boolean;
public
{ Public declarations }
end;
function ADsGetObject(const PathName: WideString; const GUID:
TGUID; out I: IUnknown): HRESULT; stdcall;
var
FRM_IIS: TFRM_IIS;
implementation
uses ActiveDs_TLB, IISExt_TLB, p_setupdata;
{$R *.dfm}
function ADsGetObject; external 'activeds.dll' name 'ADsGetObject';
//创建IIS站点
function Tfrm_iis.ConfigWebServer: Boolean;
var
I: IADsContainer;
ADs: IADs;
ServerObj: IADs;
begin
try
try
screen.Cursor := crHourGlass;
if ADsGetObject('IIS://localhost/w3svc', IID_IADsContainer, IUnknown(I)) = S_Ok then
begin
//create a new virtual server at the service,数字2是站点号,1是默认的WEB站点,你可以改成其他的,如8,9等
ServerObj := IADs(I.Create('IIsWebServer', edwebnum.text));
//configure new server
ServerObj.Put('ServerSize', 1); // Medium-sized server
ServerObj.Put('ServerComment', edComment.text);
ServerObj.put('ServerBindings', edIPAddress.text + ':' + edPort.text + ':');
// Write info back to Metabase,80是端口号
// ServerObj.put('ServerBindings', ':80:');
ServerObj.SetInfo;
if ServerObj.QueryInterface(IID_IADsContainer, I) = S_OK then
begin
//create virtual root directory
ADs := IADs(I.Create('IIsWebVirtualDir', 'Root'));
//Configure new virtual root
ADs.put('Path', edCommentPath.Text); //站点路径
ADs.put('AccessRead', 'True'); //存取权限设置,这里是设置读权限,具体的资料你可以看MSDN
//ADs.put('AccessWrite','True');
ADs.put('AccessScript', 'True'); //设置脚本权限
ADs.put('EnableDefaultDoc', 'True'); //设置允许默认文档
//Configure Default Document as "index.asp"
ADs.put('DefaultDoc', 'default.htm'); //将默认文档设置为"index.asp",你可以设置成自己需要的
//ADs.put('EnableDirBrowsing','F');
//Write info back to Metabase
ADs.SetInfo;
(ADs as IISApp).AppCreate(true);
end;
end;
if cbStartIIS.Checked = True then //create and start the web
begin
if ADsGetObject('IIS://localhost/w3svc', IID_IADsContainer, IUnknown(I)) = S_Ok then
begin
ADs := IADs(I.GetObject('IIsWebServer', edwebnum.text));
(ADs as IADsServiceOperations).start;
end;
end;
//start the service
finally
screen.Cursor := crdefault;
end;
Result := true;
except
Result := false;
end; // try/except
end;