VBS建立站点代码
Function CreateWebServer(strServerComment,arrServerBindings,strMaxConnections,strPath)'建立站点
On Error Resume Next
Set objW3svc = GetObject("IIS://LocalHost/W3svc")
intSiteIndex = 999
Do While IsObject(objW3svc.GetObject("IIsWebServer",intSiteIndex))
If Err.Number <> 0 Then
'Wscript.Echo Err.Description
Err.Clear()
Exit Do
End If
intSiteIndex = intSiteIndex - 1
Loop
Set objIIs = objW3svc.Create("IIsWebServer",intSiteIndex)
If Err.Number <> 0 Then
Wscript.Echo "Error # " & CStr(Err.Number) & " " & Err.Description
Err.Clear()
CreateWebServer = 0
Exit Function
End If
objIIs.ServerSize = 1
objIIs.ServerComment = strServerComment
objIIs.ServerBindings = arrServerBindings
objIIs.MaxConnections = strMaxConnections
objIIs.EnableDefaultDoc = True
objIIs.SetInfo
Set objIIsWeb = objIIs.Create("IIsWebVirtualDir", "Root")
If Err.Number <> 0 Then
Wscript.Echo "Error # " & CStr(Err.Number) & " " & Err.Description
Err.Clear()
CreateWebServer = 0
Exit Function
End If
objIIsWeb.Path = strPath
objIIsWeb.AccessRead = True
objIIsWeb.AccessWrite = False
objIIsWeb.EnableDirBrowsing = False
objIIsWeb.EnableDefaultDoc = True
objIIsWeb.AccessScript = True
objIIsWeb.AppIsolated = 2
objIIsWeb.AppCreate2 2
objIIsWeb.AppFriendlyName = "默认应用程序"
objIIsWeb.SetInfo
Set objW3svc = Nothing
Set objIIs = Nothing
Set objIIsWeb = Nothing
CreateWebServer = 1
End Function
Function CreateWebServer(strServerComment,arrServerBindings,strMaxConnections,strPath)'建立站点
On Error Resume Next
Set objW3svc = GetObject("IIS://LocalHost/W3svc")
intSiteIndex = 999
Do While IsObject(objW3svc.GetObject("IIsWebServer",intSiteIndex))
If Err.Number <> 0 Then
'Wscript.Echo Err.Description
Err.Clear()
Exit Do
End If
intSiteIndex = intSiteIndex - 1
Loop
Set objIIs = objW3svc.Create("IIsWebServer",intSiteIndex)
If Err.Number <> 0 Then
Wscript.Echo "Error # " & CStr(Err.Number) & " " & Err.Description
Err.Clear()
CreateWebServer = 0
Exit Function
End If
objIIs.ServerSize = 1
objIIs.ServerComment = strServerComment
objIIs.ServerBindings = arrServerBindings
objIIs.MaxConnections = strMaxConnections
objIIs.EnableDefaultDoc = True
objIIs.SetInfo
Set objIIsWeb = objIIs.Create("IIsWebVirtualDir", "Root")
If Err.Number <> 0 Then
Wscript.Echo "Error # " & CStr(Err.Number) & " " & Err.Description
Err.Clear()
CreateWebServer = 0
Exit Function
End If
objIIsWeb.Path = strPath
objIIsWeb.AccessRead = True
objIIsWeb.AccessWrite = False
objIIsWeb.EnableDirBrowsing = False
objIIsWeb.EnableDefaultDoc = True
objIIsWeb.AccessScript = True
objIIsWeb.AppIsolated = 2
objIIsWeb.AppCreate2 2
objIIsWeb.AppFriendlyName = "默认应用程序"
objIIsWeb.SetInfo
Set objW3svc = Nothing
Set objIIs = Nothing
Set objIIsWeb = Nothing
CreateWebServer = 1
End Function
If Err.Number <> 0 Then 在VBS里经常看到这种代码。