//在DELPHI中用ADSI来控制IIS,检测、增加、删除虚拟目录 ////////// ////////// //以下程序均从大富翁及网上所得,非本人所原创,感谢原作者 //本人只是觉得有用,将其整理,希望对大家有用 //英腾软件:QQ:815825,欢迎交流编程知识 ////////// //////////
//删除虚拟目录应用程序名 function DeleteVirtualDirApp(strVirtualDir: string): Boolean; var WebSite, WebServer, WebRoot, vdir: Variant; begin Result := True; try WebSite := CreateOleObject('IISNamespace'); WebSite := WebSite.GetObject('IIsWebService', 'localhost/w3svc'); WebServer := WebSite.GetObject('IIsWebServer', '1'); WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root'); vdir := WebRoot.GetObject('IIsWebVirtualDir', strVirtualDir); vdir.AppDelete; vdir.SetInfo; except Result := False; end;
end;
//删除虚拟目录 function DeleteVirtualDir(strVirtualDir: string): Boolean; var WebSite, WebServer, WebRoot, vdir: Variant; begin Result := True; try WebSite := CreateOleObject('IISNamespace'); WebSite := WebSite.GetObject('IIsWebService', 'localhost/w3svc'); WebServer := WebSite.GetObject('IIsWebServer', '1'); WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root'); WebRoot.Delete('IIsWebVirtualDir', strVirtualDir); except Result := False; end; end;
{检测是否有虚拟目录} function CheckVirtualDir(const strVirtualDir: string): Boolean; var WebSite, WebServer, WebRoot, vdir: Variant; begin Result := True; try WebSite := CreateOleObject('IISNamespace'); WebSite := WebSite.GetObject('IIsWebService', 'localhost/w3svc'); WebServer := WebSite.GetObject('IIsWebServer', '1'); WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root'); WebRoot.GetObject('IIsWebVirtualDir', strVirtualDir); except Result := False; end; end;
//建立虚拟目录 function CreateVirtualDir(const strVirtualDir, strDir, strAppName: string): Boolean; var WebSite, WebServer, WebRoot, vdir: Variant; begin Result := True; try WebSite := CreateOleObject('IISNamespace'); WebSite := WebSite.GetObject('IIsWebService', 'localhost/w3svc'); WebServer := WebSite.GetObject('IIsWebServer', '1'); WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root'); vdir := WebRoot.Create('IIsWebVirtualDir', strVirtualDir); vdir.AccessRead := True;
vdir.AccessScript := True; //执行许可为纯脚本 vdir.DefaultDoc := 'index.aspx,index.asp'; //默认文档 vdir.EnableDirBrowsing := False; vdir.AppFriendlyName := strAppName; //应用程序名 vdir.Path := strDir; vdir.AppCreate(True); //如果没有这句的话,虚拟目录就要人为的手工创建应用程序名 vdir.SetInfo; except Result := False; end; end; |