在IIS建虚拟目录运行时报“OLE error 80005008”?原因何在?? (200分)

  • 主题发起人 主题发起人 xianxiliu
  • 开始时间 开始时间
X

xianxiliu

Unregistered / Unconfirmed
GUEST, unregistred user!
在编译时没错。。运行时有错!错如上。
procedure TForm1.Button2Click(Sender: TObject);
var
I: IADsContainer; ADs: IADs;
begin
if ADsGetObject('IIS://localhost', IID_IADsContainer, IUnknown(I)) = S_Ok then begin //IIS已經安裝
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('001web', 'Root')); //在Web伺服器的Root下建立虛擬目錄
********上面的这句运行时出错!编译时无任何错误********************************************
if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then begin //服務支持
try
ADs := IADs(I.Create('001web', '001web')); //建立虛擬目錄,別名為edtAlias.Text
except
Application.MessageBox('這個別名已經存在,請選擇另外的別名!','警告');
Exit;
end; //try except
Application.MessageBox('您的設定已經保存。','恭喜');
end;
end;
end;
end else
Application.MessageBox('您的電腦上沒有安裝IIS或者您無權訪問IIS。','警告');
end;
错误信息如题,运行时出错的语句在**内
 
if ADsGetObject('IIS://localhost/w3svc', IID_IADsContainer, IUnknown(I)) = S_Ok then
begin
//create a new virtual server at the service
ServerObj := IADs(I.Create('IIsWebServer', aaa));//aaa是一个数字
//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 edIPAddress.text 是IP地址,edPort.text 是端口号
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');//设置权限
ADs.put('AccessScript', 'True');
ADs.put('EnableDefaultDoc', 'True');//设置是否允许默认文档
//Configure Default Document as "index.asp"
ADs.put('DefaultDoc', 'index.asp');
//ADs.put('EnableDirBrowsing','F');
//Write info back to Metabase
ADs.SetInfo;
(ADs as IISApp).AppCreate(true);
end;
end;
之前要导入ActiveDs_TLB, IISExt_TLB库,也就是导入adsi的那几个库
 
TO: lzhuan
最后一句: (ADs as IISApp).AppCreate(true);
报错:[Error] setdatapas.pas(339): Undeclared identifier: 'IISApp'
 
有可能是你的几个库文件没有导入吧。
给你一段比较完整的代码,请确认已经导入ActiveDs_TLB, IISExt_TLB库
====================
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';

function Tfrm_iis.CheckInput: Boolean;
begin
if (edComment.Text = '') or (edIPAddress.Text = '') or (edwebnum.Text='') then
begin
Result := false;
end
else
begin
Result := true;
end;
end;

//创建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
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;
//设置新建站点下的一个虚拟目录
function Tfrm_iis.ConfigWebVirtualCGIBIN: Boolean;
var
I: IADsContainer;
ADs: IADs;
begin
try
try
screen.Cursor := crHourGlass;
if ADsGetObject('IIS://localhost/w3svc', IID_IADsContainer, IUnknown(I)) = S_Ok then
begin
ADs := IADs(I.GetObject('IIsWebServer', '11'));
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', 'cgi-bin'));
ADs.Put('AccessRead', 'True');
ADs.Put('AccessExecute', 'True');
ADs.Put('Path', edCommentPath.Text + '/cgi-bin');
ADs.put('EnableDefaultDoc', 'False');
ADs.SetInfo;
end;
end;
end;
finally // wrap up
screen.Cursor := crdefault;
end; // try/finally
Result := true;
except
Result := false;
end; // try/except
end;
//=================================
以上代码是我程序里截出来的。
 
议会关注!!
 
ServerObj := IADs(I.Create('IIsWebServer', edwebnum.text));
//create a new virtual server at the service,数字2是站点号,1是默认的WEB站点,你可以改成其他的,如8,9等

这里面的数字。1,2,3或其它,是随便写的吗???为什么。。哪个详细帮忙上一下课!
 
實際操作一下,就會明白:)
 
lzhuan, 你好:
我看了你的回贴,发现你很精通IIS这一部分。
我现在也在用程序实现这个功能,除了你提到的,我还有以下的问题:
当我使用了下面的代码:
(ADs as IISApp).AppCreate(TRUE);
发现是创建了应用程序,可是应用程序名是空白的,请问如何设置?
还有,就是[应用程序保护]如何设置呢?
还望您不吝赐教! 等待您的回应。
 
后退
顶部