我在网上找了一个创建web虚拟目录的文章其中有三个例子,但只有一个能运行,但没有删除虚拟目录代码?
先引入类型库(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.执行代码如下:
uses
ComObj,IISOle_TLB, ActiveDs_TLB; procedure TForm1.MakeVirtualDir(path, vdname: string);
var
Disp: IDispatch; begin
Disp := CreateOleObject('IISNamespace');
Disp := (Disp as 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',vdname);
(Disp as IADs).Put('AccessRead', 'True');
(Disp as IADs).Put('Path', path);
(Disp as IADs).SetInfo;
end;
procedure TForm1.DeleteVirtualDir(vdname:string);
var
Disp: IDispatch;
begin
try
Disp := CreateOleObject('IISNamespace');
Disp := (Disp as IISNamespace).GetObject('IIsWebService', 'localhost/w3svc');
Disp := (Disp as IADsContainer).GetObject('IIsWebServer', '1');
Disp := (Disp as IADsContainer).GetObject('IIsWebVirtualDir', 'Root');
Disp := (Disp as IADsContainer).Delete('IIsWebVirtualDir', vdname);
except
//messagebox(application.Handle,pchar('无法删除。'),'提示',MB_ICONStop);
end;
end;我现在可以MakeVirtualDir过程新建虚拟目录,但是删除语句:
Disp := (Disp as IADsContainer).Delete('IIsWebVirtualDir', vdname);
这句语句编译报错:
[Error] Unit1.pas(1017): Incompatible types: 'procedure, untyped pointer or untyped parameter' and 'IDispatch'
请高手指点,高分相送。
先引入类型库(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.执行代码如下:
uses
ComObj,IISOle_TLB, ActiveDs_TLB; procedure TForm1.MakeVirtualDir(path, vdname: string);
var
Disp: IDispatch; begin
Disp := CreateOleObject('IISNamespace');
Disp := (Disp as 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',vdname);
(Disp as IADs).Put('AccessRead', 'True');
(Disp as IADs).Put('Path', path);
(Disp as IADs).SetInfo;
end;
procedure TForm1.DeleteVirtualDir(vdname:string);
var
Disp: IDispatch;
begin
try
Disp := CreateOleObject('IISNamespace');
Disp := (Disp as IISNamespace).GetObject('IIsWebService', 'localhost/w3svc');
Disp := (Disp as IADsContainer).GetObject('IIsWebServer', '1');
Disp := (Disp as IADsContainer).GetObject('IIsWebVirtualDir', 'Root');
Disp := (Disp as IADsContainer).Delete('IIsWebVirtualDir', vdname);
except
//messagebox(application.Handle,pchar('无法删除。'),'提示',MB_ICONStop);
end;
end;我现在可以MakeVirtualDir过程新建虚拟目录,但是删除语句:
Disp := (Disp as IADsContainer).Delete('IIsWebVirtualDir', vdname);
这句语句编译报错:
[Error] Unit1.pas(1017): Incompatible types: 'procedure, untyped pointer or untyped parameter' and 'IDispatch'
请高手指点,高分相送。
解决方案 »
- dll创建窗体过后就乱码
- 帮忙,.100RMB求老师帮忙写个HTTPS网业自动登陆程序
- RZCheckTree 读取数据库的值
- 这个VB的一点函数,delphi怎么写?
- Delphi~~~/C/c++
- 怎样对查询的结果再查询??
- 急,请问怎么才能将文件拖到控件里面
- 我想复制部分列的数据,帮我
- 在线等待!!!各位高手,你们好!我现请教一个关于查询的问题,在此查询中涉及到金额的问题,但有重复数据.
- 查询出来的数据如何处理后显示,但是不影响数据库的信息
- 急, 请问高手关于Delphi6写 程序后安装的问题,回答者给分!! 在线等待
- 如何调节PrintDBGridEh1第三方控件的预览边界及设定横向打印??
脚本的代码,没有时间给你翻译到delphi了,你自己翻译吧。
都是使用了adsi,和你使用IIS的原理是一样的。
<%on error resume nextsComputer ="localhost"
sPhyDir = "c:\dina\adsi"
sVirDir = "ADSITest"'Get Default Web Site Object
set websvc = GetObject("IIS://" & sComputer & "/W3svc/1")'Verify by printing out ServerComment
Response.Write "Comment = " & websvc.ServerComment & "<br>"'Get root of Default Web Site
set vRoot = websvc.GetObject("IIsWebVirtualDir", "Root")'Delete Virtual Directory
Set vDir = vRoot.Delete("IIsWebVirtualDir",sVirDir)
%>
删除一个虚拟目录在这个例子中,你将学习到如何删除一个虚拟目录。当建立一个对象时,你必须有它的父对象。这
个真理也同样适用于删除。例七表明了如何做。
Example 7
<%
on error resume nextsComputer ="localhost"
sPhyDir = "c:\dina\adsi"
sVirDir = "ADSITest"'Get Default Web Site Object
set websvc = GetObject("IIS://" & sComputer & "/W3svc/1")'Verify by printing out ServerComment
Response.Write "Comment = " & websvc.ServerComment & "<br>"'Get root of Default Web Site
set vRoot = websvc.GetObject("IIsWebVirtualDir", "Root")'Delete Virtual Directory
Set vDir = vRoot.Delete("IIsWebVirtualDir",sVirDir)
%> 我在大富翁上也发了帖子。
谢谢搂上的前辈指点,我就是这样翻译的代码编译就是不通过。
在线等待高手,我想只是看一个删除的小例子。
<%
on error resume nextsComputer ="localhost"
sPhyDir = "c:\dina\adsi"
sVirDir = "ADSITest"'Get Default Web Site Object
set websvc = GetObject("IIS://" & sComputer & "/W3svc/1")'Verify by printing out ServerComment
Response.Write "Comment = " & websvc.ServerComment & "<br>"'Get root of Default Web Site
set vRoot = websvc.GetObject("IIsWebVirtualDir", "Root")'Delete Virtual Directory
Set vDir = vRoot.Delete("IIsWebVirtualDir",sVirDir)
%>