' Open the object for the first virtual Web server root
Set WebServerRootObj = GetObject("IIS://MyComputer/W3SVC/1/Root")
' Deny write access for all directories and files
' for the server (except those already specifically set)
' Using the Put method
WebServerRootObj.Put "AccessWrite", False
' Save the changed value to the metabase
WebServerRootObj.SetInfo
' Get a directory subordinate to the Web server root. Note that this line of code assumes
' Vdir1 has already been created.
Set VDirObj = GetObject("IIS://MyComputer/W3SVC/1/Root/Vdir1/Dir1a")
' Overwrite the inherited value for write access
' using the dot method equivalent to Put
VDirObj.AccessWrite = True
' Save the changed value to the metabase
VDirObj.SetInfo
%>
ADSI ASP Script
The next example shows you how to write a customized script to create a virtual directory with Read, Script, and Directory browsing permission.
<%
'''''''''''''''''''''''''''''''''
' ADSI ASP Sample Program
' This is a sample of how to create a virtual directory using ADSI.
'
'''''''''''''''''''''''''''''''''
Option Explicit
On Error Resume Next
'''''''''''''''''''''''
' First, open the path to the Web server you are
' trying to add a virtual directory to.
Dim ServObj
Dim VdirObj
Dim Testpath
Set ServObj = GetObject("IIS://LocalHost/w3svc/1/Root")
if (Err <>0) then
Response.Write "GetObject (""IIS://LocalHost/w3svc/1/Root"") Failed! <br>"
Response.Write "Error! " & Err.Number & "(" & Hex(Err.Number) & "): " & Err.Description & "<br>"
Response.End
end if
'''''''''''''''''''''''
' Second, Create the virtual directory (Vdir) path
Set VdirObj = ServObj.Create("IIsWebVirtualDir", "MyVdir")
VdirObj.SetInfo
if (Err<>0) then
Response.Write "CreateObject (""IIS://LocalHost/w3svc/1/Root/MyVdir"") Failed!<br>"
Response.Write "Error! " & Err.Number & "(" & Hex (Err.Number) & "): " & Err.Description &
"<br>"
Response.End
end if
''''''''''''''''''''''''
' Finally, create a Path variable containing the virtual root path and
' set the permissions to read, script, and directory browsing
VdirObj.AccessRead = True
VdirObj.AccessScript = True
VdirObj.EnableDirBrowsing = True
Testpath = "C:\Temp"
VdirObj.Put "Path", (Testpath)
Public Function CreateFtpSite(ByVal strComputerName As String, strIPAddress As String, ByVal strRootDirectory As String, ByVal strServerComment As String, ByVal iPortNum As Integer, ByVal bStart As Boolean, ByVal iSiteNumber As Integer, ByVal strUserName As String, ByVal strPassword As String)
Dim bDone
Dim oFtpServer
Dim oFtpSite
Dim oMsFtpSvc
Dim oNewFtpServer
Dim oNewDir
Dim oNewDirInfo
Err.Clear
On Error Resume Next
'取FTP服务地址
Set oMsFtpSvc = GetObject("IIS://" & strComputerName & "/MSFTPSVC")
If Err.Number <> 0 Then
MsgBox "不能打开: " & "IIS://" & strComputerName & "/MSFTPSVC"
Exit Function
End If
Set oNewFtpServer = oMsFtpSvc.Create("IIsFtpServer", iSiteNumber)
oNewFtpServer.SetInfo
If (Err.Number <> 0) Then
MsgBox "不能创建FTP站点. 可能是站点索引号已存在. 站点索引号: " & iSiteNumber
Exit Function
End If
'启动新的FTP站点
If bStart = True Then
Err.Clear
oNewFtpServer.Start
If Err.Number <> 0 Then
MsgBox strServerComment & "无法自动启动,请察看是否有使用相同端口的FTP服务正在运行"
End If
End If