=============================================================
' 感謝您使用ASP001工作室開發的實用函數程序
' HTTP://WWW.ASP001.NET
'=============================================================
'ASP001工作室為您提供訂制程序開發、企業互聯網拓展服務
'QQ:1974229
'E-Mail:
[email protected] '更多程序下載請到HTTP://WWW.ASP001.NET
'=============================================================
'函數介紹:創建WebSite
'本函數使用ADSI,需要Administrators組用戶權限
'函數名稱:CreateWebSite(Computer,IPAddr,PortNum,HostName,WebSiteDirectory,LogDirectory,WebSiteInfo,GuestUserName,GuestUserPass,StartOrStop)
'程序開發:ASP001工作室 ChuQi
'用法:CreateWebSite 計算機名(一搬為LocalHost或127.0.0.1),站點IP地址,端口號,主機名,站點根目錄,,LOG文件的目錄站點說明,網站訪問時所使用的帳號,網站訪問時所用帳號的口令,是否啟動站點
'例:CreateWebSite "LocalHost","127.0.0.123","80","www.test.net","E:\UserData\UserNum001","E:\UserData\UserNum001\LogFiles","wwwtest.net","IUSR_Num001_test.net","abc888",True
'=============================================================
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 = "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
Else
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
Else
End If
End If
response.write "站點創建成功,站點編號為:"& SiteNum &" ,域名為:"& HostName
End Function