Public Function WebVirtualDir(ByVal strWebSite As String, ByVal strFriendlyName As String, ByVal strWebPath As String, ByVal strDefaultDoc As String) As Boolean
Dim objADSI As Object
Dim objWebVDir As Object
On Error GoTo Lib_Err
Set objADSI = GetObject("IIS://LocalHost/W3SVC/1/Root")
Set objWebVDir = objADSI.Create("IIsWebVirtualDir", strWebSite)
objWebVDir.SetInfo
Set ServObj = GetObject("IIS://LocalHost/w3svc/1/Root")
PassFail "Open Web server"
' delete old app
Set VdirObj = ServObj.GetObject("IIsWebVirtualDir", "LearnBizTalk")
VdirObj.SetInfo
VdirObj.AppDelete
err.clear
' delete old vdir
ServObj.Delete "IIsWebVirtualDir", "LearnBizTalk"
err.clear
' Second, Create the virtual directory (Vdir) path
Set VdirObj = ServObj.Create("IIsWebVirtualDir", "LearnBizTalk")
VdirObj.SetInfo
PassFail "Create VDir"
' Finally, create a Path variable containing the virtual root path and set the permissions to read, script
VdirObj.AccessRead = True
Testpath = "C:\LearnBizTalk\ASP"
VdirObj.Put "Path", (Testpath)
VdirObj.SetInfo
PassFail "Set VDir Path and permissions"
' create out-of-proc application
vdirObj.AppCreate False
PassFail "Create Web Application"
Sub PassFail(strScope)
If Err.Number <> 0 Then
Fail strScope & " Error: x" & Hex(Err.Number) & " Description: " & Err.Description & " Source: " & Err.Source
Err.Clear
'Else
'Pass strScope
End If
End Sub
Sub Fail(strScope)
WScript.Echo "[FAIL] " & SetGetEnvVar("PROCESS", "ComputerName", "DEFAULTSERVER", False) & ":" & strScope
MsgBox "Setup did not complete!", 16
WScript.Quit
End Sub
虚拟目录
先引入类型库(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.
方法一(参照C++)、
var
I: IADsContainer;
ADs: IADs;
begin
if ADsGetObject(''IIS://localhost/w3svc'', IID_IADsContainer, IUnknown(I)) = S_Ok then
begin
ADs := IADs(I.GetObject(''IIsWebServer'', ''1''));
ShowMessage(ADs.ADsPath);
if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then
begin
ADs := IADs(I.GetObject(''IIsWebVirtualDir'', ''Root''));
ShowMessage(ADs.ADsPath);
if ADs.QueryInterface(IID_IADsContainer, I) = S_OK then
begin
ADs := IADs(I.Create(''IIsWebVirtualDir'', ''DelphiTest''));
ADs.Put(''AccessRead'', ''True'');
ADs.Put(''Path'', ''c:\Temp'');
ADs.SetInfo;
end;
end;
end;
end;
方法二(使用接口)、
procedure TForm3.BitBtn4Click(Sender: TObject);
var
Disp: IDispatch;
begin
Disp := IISNamespace1.GetObject(''IIsWebService'', ''localhost/w3svc'');
Disp := (Disp as IADsContainer).GetObject(''IIsWebServer'', ''1'');
Disp := (Disp as IADsContainer).GetObject(''IIsWebVirtualDir'', ''Root'');
Disp := (Disp as IADsContainer).Create(''IIsWebVirtualDir'', ''DelphiADSITest'');
(Disp as IADs).Put(''AccessRead'', ''True'');
(Disp as IADs).Put(''Path'', ''c:\ADSITest'');
(Disp as IADs).SetInfo;
end;