在网上查的资料可以建立虚拟目录,但其没有指定应用程序名,还需要手动进入INTERNET服务管理里,在其属性内点击"创建"才行,不知是差哪一个属性没有指定.代码如下:unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Activeds_TLB,comobj;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations } public
{ Public declarations }
end;
function ADsGetObject(const PathName: WideString; const GUID:TGUID; out I: IUnknown): HRESULT; stdcall;
var
Form1: TForm1;implementation{$R *.dfm}
function ADsGetObject;external 'ActiveDS.dll' name 'ADsGetObject';procedure TForm1.Button1Click(Sender: TObject);
var
I: IADsContainer;
ADs: IADs;
begin
if ADsGetObject('IIS://localhost', IID_IADsContainer, IUnknown(I)) = S_Ok then //IIS已?安?
begin
if ADsGetObject('IIS://localhost/w3svc', IID_IADsContainer, IUnknown(I)) = S_Ok then
begin //Web伺服器存在
ADs := IADs(I.GetObject('IIsWebServer', '1')); //取得服?
if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then
begin //服?支持
ADs := IADs(I.GetObject('IIsWebVirtualDir', 'Root')); //在Web伺服器的Root下建立??目?
if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then begin //服?支持
try
ADs := IADs(I.Create('IIsWebVirtualDir', 'myxh416')); //虚拟目录
except
Application.MessageBox('别名已经存在!','警告');
Exit;
end; //try except ADs.Put('AccessRead', true);//********属性都在这里**********
ADs.Put('AccessWrite',false);
ADs.put('AccessScript',false);
ADs.Put('AccessExecute',true);
ADs.put('EnableDirBrowsing',false);
//ADs.put('Createprprogram',false);
ADs.Put('Path', 'e:\fire');
ADs.Put('DefaultDoc','Default.htm');
ADs.Put('EnableDefaultDoc',True);//允许打开默认文件
ADs.SetInfo; //保存??
Application.MessageBox('您的IIS虚拟目录已配置成功!。','恭喜');
end;
end;
end;
end
else
Application.MessageBox('您的IIS虚拟目录已配置没有成功!','警告');
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Activeds_TLB,comobj;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations } public
{ Public declarations }
end;
function ADsGetObject(const PathName: WideString; const GUID:TGUID; out I: IUnknown): HRESULT; stdcall;
var
Form1: TForm1;implementation{$R *.dfm}
function ADsGetObject;external 'ActiveDS.dll' name 'ADsGetObject';procedure TForm1.Button1Click(Sender: TObject);
var
I: IADsContainer;
ADs: IADs;
begin
if ADsGetObject('IIS://localhost', IID_IADsContainer, IUnknown(I)) = S_Ok then //IIS已?安?
begin
if ADsGetObject('IIS://localhost/w3svc', IID_IADsContainer, IUnknown(I)) = S_Ok then
begin //Web伺服器存在
ADs := IADs(I.GetObject('IIsWebServer', '1')); //取得服?
if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then
begin //服?支持
ADs := IADs(I.GetObject('IIsWebVirtualDir', 'Root')); //在Web伺服器的Root下建立??目?
if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then begin //服?支持
try
ADs := IADs(I.Create('IIsWebVirtualDir', 'myxh416')); //虚拟目录
except
Application.MessageBox('别名已经存在!','警告');
Exit;
end; //try except ADs.Put('AccessRead', true);//********属性都在这里**********
ADs.Put('AccessWrite',false);
ADs.put('AccessScript',false);
ADs.Put('AccessExecute',true);
ADs.put('EnableDirBrowsing',false);
//ADs.put('Createprprogram',false);
ADs.Put('Path', 'e:\fire');
ADs.Put('DefaultDoc','Default.htm');
ADs.Put('EnableDefaultDoc',True);//允许打开默认文件
ADs.SetInfo; //保存??
Application.MessageBox('您的IIS虚拟目录已配置成功!。','恭喜');
end;
end;
end;
end
else
Application.MessageBox('您的IIS虚拟目录已配置没有成功!','警告');
end;end.
ADs.Put('AccessWrite',false);
ADs.put('AccessScript',false);
ADs.Put('AccessExecute',true);
ADs.put('EnableDirBrowsing',false);
//ADs.put('Createprprogram',false);
ADs.Put('Path', 'e:\fire');
ADs.Put('DefaultDoc','Default.htm');
ADs.Put('EnableDefaultDoc',True);//允许打开默认文件
应该是这些属性中的,还有些属性没有列出来,可我不知道哪里可以查到,有谁知道呢?
InstallPath: String;
WebSite, WebServer, WebRoot, VDir: Variant;
begin
WebSite := CreateOleObject('IISNamespace');
WebSite := WebSite.GetObject('IIsWebService', 'localhost/w3svc');
WebServer := WebSite.GetObject('IIsWebServer', '1');
webserver.setinfo;
WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root');
VDir := WebRoot.Create('IIsWebVirtualDir', 'VariantTest');
VDir.AccessRead := True;
VDir.Path := 'C:\test';
VDir.AppCreate(True); //只要加上这一句 VDir.SetInfo;