本文介绍使用ASP或VB、VBScript在IIS中创建WEB站点。这是一个写好的函数,可以直接使用。'============================================================='函数介绍:创建WebSite'本函数使用ADSI,需要Administrators组用户权限'函数名称:CreateWebSite(Computer,IPAddr,PortNum,HostName,WebSiteDirectory,LogDirectory,WebSiteInfo,GuestUserName,GuestUserPass,StartOrStop)'用法: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, NewDirDim Bindings, BindingString, NewBindings, SiteNum, SiteObj, bDoneOn Error Resume NextErr.Clear'检测是否能够加载W3SVC服务(即WEB服务)Set w3svc = GetObject("IIS://" & Computer & "/w3svc")If Err.Number <> 0 Then '显示错误提示response.write "无法打开: "&"IIS://" & Computer & "/w3svc"response.endEnd If'检测是否有设定相同IP地址、端口及主机名的站点存在BindingString = IPAddr & ":" & PortNum & ":" & HostNameFor Each WebServer in w3svcIf WebServer.Class = "IIsWebServer" ThenBindings = WebServer.ServerBindingsIf BindingString = Bindings(0) Thenresponse.write "IP地址冲突:" & IPAddr & ",请检测IP地址!."Exit FunctionEnd IfEnd IfNext'确定一个不存在的站点编号做为新建站点编号,系统默认WebSite站点编号为1,因此从2开始SiteNum=2bDone = FalseWhile (Not bDone)Err.ClearSet SiteObj = GetObject("IIS://"&Computer&"/w3svc/"&SiteNum) '加载指定站点If (Err.Number = 0) Then'response.write " Step_1站点"&SiteNum&"存在"SiteNum = SiteNum + 1Else'response.write " Step_1站点"&SiteNum&"不存在"Err.ClearSet NewWebServer = w3svc.Create("IIsWebServer",SiteNum) '创建指定站点If (Err.Number <> 0) Then'response.write " Step_2站点"&SiteNum&"创建失败"SiteNum = SiteNum + 1Else'response.write " Step_2站点"&SiteNum&"创建成功"bDone = TrueEnd IfEnd IfIf (SiteNum > 50) Then '服务器最大创建站点数response.write "超出服务器最大创建站点数,正在创建的站点的序号为: "&SiteNum&"."response.endEnd IfWend'进行站点基本配置NewBindings = Array(0)NewBindings(0) = BindingStringNewWebServer.ServerBindings = NewBindingsNewWebServer.ServerComment= WebSiteInfoNewWebServer.AnonymousUserName= GuestUserNameNewWebServer.AnonymousUserPass= GuestUserPassNewWebServer.KeyType = "IIsWebServer"NewWebServer.FrontPageWeb = TrueNewWebServer.EnableDefaultDoc = TrueNewWebServer.DefaultDoc = "Default.htm, Default.asp, Index.htm, Index.asp"NewWebServer.LogFileDirectory= LogDirectoryNewWebServer.SetInfoSet NewDir = NewWebServer.Create("IIsWebVirtualDir", "ROOT")NewDir.Path = WebSiteDirectoryNewDir.AccessRead = trueNewDir.AppFriendlyName = "应用程序" & WebSiteInfoNewDir.AppCreate TrueNewDir.AccessScript = TrueErr.ClearNewDir.SetInfoIf (Err.Number <> 0) Thenresponse.write "主目录创建时出错."response.endEnd IfIf StartOrStop = True ThenErr.ClearSet NewWebServer = GetObject("IIS://" & Computer & "/w3svc/" & SiteNum)NewWebServer.StartIf Err.Number <> 0 Thenresponse.write "启动站点时出错!"response.endErr.ClearEnd IfEnd Ifresponse.write "站点创建成功,站点编号为:"& SiteNum &" ,域名为:"& HostNameEnd Function