Function CreateWebSite(Computer,IPAddr,PortNum,HostName,WebSiteDirectory,LogDirectory,WebSiteInfo,GuestUserName,GuestUserPass,StartOrStop)
Dim w3svc, WebServer, NewWebServer, NewDir
Dim Bindings, BindingString, NewBindings, SiteNum, SiteObj, bDone
On Error Resume Next
Err.Clear
'检测是否能够加载W3SVC服务(即WEB服务)
Set w3svc = GetObject("IIS://" & Computer & "/w3svc")
If Err.Number <> 0 Then '显示错误提示
response.write "无法打开: "&"IIS://" & Computer & "/w3svc"
response.end
End If
'检测是否有设定相同IP地址、端口及主机名的站点存在
BindingString = IPAddr & ":" & PortNum & ":" & HostName
For Each WebServer in w3svc
If WebServer.Class = "IIsWebServer" Then
Bindings = WebServer.ServerBindings
If BindingString = Bindings(0) Then
response.write "IP地址冲突:" & IPAddr & ",请检测IP地址!."
Exit Function
End If
End If
Next
'确定一个不存在的站点编号做为新建站点编号,系统默认WebSite站点编号为1,因此从2开始
SiteNum=2
bDone = False
While (Not bDone)
Err.Clear
Set SiteObj = GetObject("IIS://"&Computer&"/w3svc/"&SiteNum) '加载指定站点
If (Err.Number = 0) Then
'response.write " Step_1站点"&SiteNum&"存在"
SiteNum = SiteNum + 1
Else
'response.write " Step_1站点"&SiteNum&"不存在"
Err.Clear
Set NewWebServer = w3svc.Create("IIsWebServer",SiteNum) '创建指定站点
If (Err.Number <> 0) Then
'response.write " Step_2站点"&SiteNum&"创建失败"
SiteNum = SiteNum + 1
Else
'response.write " Step_2站点"&SiteNum&"创建成功"
bDone = True
End If
End If
If (SiteNum > 50) Then '服务器最大创建站点数
response.write "超出服务器最大创建站点数,正在创建的站点的序号为: "&SiteNum&"."
response.end
End If
Wend
'进行站点基本配置
NewBindings = Array(0)
NewBindings(0) = BindingString
NewWebServer.ServerBindings = NewBindings
NewWebServer.ServerComment= WebSiteInfo
NewWebServer.AnonymousUserName= GuestUserName
NewWebServer.AnonymousUserPass= GuestUserPass
NewWebServer.KeyType = "IIsWebServer"
NewWebServer.FrontPageWeb = True
NewWebServer.EnableDefaultDoc = True
NewWebServer.DefaultDoc = "index.php,Default.htm, Default.asp, Index.htm, Index.asp"
NewWebServer.LogFileDirectory= LogDirectory
NewWebServer.SetInfo
Set NewDir = NewWebServer.Create("IIsWebVirtualDir", "ROOT")
NewDir.Path = WebSiteDirectory
NewDir.AccessRead = true
NewDir.AppFriendlyName = "应用程序" & WebSiteInfo
NewDir.AppCreate True
NewDir.AccessScript = True
Err.Clear
NewDir.SetInfo
If (Err.Number <> 0) Then
response.write "主目录创建时出错."
response.end
End If
If StartOrStop = True Then
Err.Clear
Set NewWebServer = GetObject("IIS://" & Computer & "/w3svc/" & SiteNum)
NewWebServer.Start
If Err.Number <> 0 Then
response.write "启动站点时出错!"
response.end
Err.Clear
End If
End If
response.write "站点创建成功,站点编号为:"& SiteNum &" ,域名为:"& HostName