<p><font face="Verdana">程序代码: </font></p>
<p><font face="Verdana">'=========================================================='<br>函数介绍:创建WebSite<br>'本函数使用ADSI,需要Administrators组用户权限<br>'函数名称:CreateWebSite(Computer,IPAddr,PortNum,HostName,WebSiteDirectory,LogDirectory,WebSiteInfo,<br>GuestUserName,GuestUserPass,StartOrStop)<br>'用法:CreateWebSite 计算机名(一搬为LocalHost或127.0.0.1),站点IP地址,端口号,主机名,站点根目录,,LOG文件的目录站点说明,网站访问时所使用的帐号,网站访问时所用帐号的口令,是否启动站点<br>'例:CreateWebSite "LocalHost","127.0.0.123","80","www.test.net","E:UserDataUserNum001",<br>"E:UserDataUserNum001LogFiles","CnKnow.Com","IUSR_Num001_test.net",<br>"abc888",True<br>'==================================================<br>Function CreateWebSite(Computer,IPAddr,PortNum,HostName,WebSiteDirectory,LogDirectory,WebSiteInfo,<br>GuestUserName,GuestUserPass,StartOrStop)<br>Dim w3svc, WebServer, NewWebServer, NewDir<br>Dim Bindings, BindingString, NewBindings, SiteNum, SiteObj, bDone<br>On Error Resume Next<br>Err.Clear<br>'检测是否能够加载W3SVC服务(即WEB服务)<br>Set w3svc = GetObject("IIS://" & Computer & "/w3svc")<br>If Err.Number <> 0 Then '显示错误提示<br> response.write "无法打开: "&"IIS://" & Computer & "/w3svc"<br> response.end<br>End If<br>'检测是否有设定相同IP地址、端口及主机名的站点存在<br>BindingString = IPAddr & ":" & PortNum & ":" & HostName<br>For Each WebServer in w3svc<br> If WebServer.Class = "IIsWebServer" Then<br> Bindings = WebServer.ServerBindings<br> If BindingString = Bindings(0) Then<br> response.write "IP地址冲突:" & IPAddr & ",请检测IP地址!."<br> Exit Function<br> End If<br> End If<br>Next</font></p>
<p><font face="Verdana">'确定一个不存在的站点编号做为新建站点编号,系统默认WebSite站点编号为1,因此从2开始<br>SiteNum=2<br>bDone = False<br>While (Not bDone)<br>Err.Clear<br>Set SiteObj = GetObject("IIS://"&Computer&"/w3svc/"&SiteNum) '加载指定站点<br>If (Err.Number = 0) Then<br> 'response.write " Step_1站点"&SiteNum&"存在"<br> SiteNum = SiteNum + 1<br>Else<br> 'response.write " Step_1站点"&SiteNum&"不存在"<br> Err.Clear<br> Set NewWebServer = w3svc.Create("IIsWebServer",SiteNum) '创建指定站点<br> If (Err.Number <> 0) Then<br> 'response.write " Step_2站点"&SiteNum&"创建失败"<br> SiteNum = SiteNum + 1<br> Else<br> 'response.write " Step_2站点"&SiteNum&"创建成功"<br> bDone = True<br> End If<br>End If<br>If (SiteNum > 50) Then '服务器最大创建站点数<br> response.write "超出服务器最大创建站点数,正在创建的站点的序号为: "&SiteNum&"."<br> response.end<br>End If<br>Wend</font></p>
<p><font face="Verdana">'进行站点基本配置<br>NewBindings = Array(0)<br>NewBindings(0) = BindingString<br>NewWebServer.ServerBindings = NewBindings<br>NewWebServer.ServerComment= WebSiteInfo<br>NewWebServer.AnonymousUserName= GuestUserName<br>NewWebServer.AnonymousUserPass= GuestUserPass<br>NewWebServer.KeyType = "IIsWebServer"<br>NewWebServer.FrontPageWeb = True<br>NewWebServer.EnableDefaultDoc = True<br>NewWebServer.DefaultDoc = "Default.htm, Default.asp, Index.htm, Index.asp"<br>NewWebServer.LogFileDirectory= LogDirectory<br>NewWebServer.SetInfo<br>Set NewDir = NewWebServer.Create("IIsWebVirtualDir", "ROOT")<br>NewDir.Path = WebSiteDirectory<br>NewDir.AccessRead = true<br>NewDir.AppFriendlyName = "应用程序" & WebSiteInfo<br>NewDir.AppCreate True<br>NewDir.AccessScript = True<br>Err.Clear<br>NewDir.SetInfo<br>If (Err.Number <> 0) Then<br> response.write "主目录创建时出错."<br> response.end<br>End If<br>If StartOrStop = True Then<br> Err.Clear<br> Set NewWebServer = GetObject("IIS://" & Computer & "/w3svc/" & SiteNum)<br> NewWebServer.Start<br> If Err.Number <> 0 Then<br> response.write "启动站点时出错!"<br> response.end<br> Err.Clear<br> End If<br>End If<br>response.write "站点创建成功,站点编号为:"& SiteNum &" ,域名为:"& HostName<br>End Function</font></p><font face="Verdana">
<p><br>使用ASP设置指定站点CPU最大使用程度<br>程序代码: </p>
<p><br>'=================================================<br>'函数介绍:设置指定站点CPU最大使用程度<br>'本函数使用ADSI,需要Administrators组用户权限<br>'函数名称:SetCPULimitVar (Computer,SiteNum,LimitVar)<br>'用法:SetCPULimitVar 计算机名,站点编号,最大限制值(100=1%,1000=10%)<br>'例:SetCPULimitVar "LocalHost","2","2000"<br>'=================================================<br>Function SetCPULimitVar(Computer,SiteNum,LimitVar)<br>Set MyObj001 = GetObject("IIS://"&Computer&"/W3SVC/"&SiteNum)<br>'设置启用CPU限制<br>MyObj001.CpuLimitsEnabled = True<br>'设置限制使用额度值<br>MyObj001.CpuLimitLogEvent=LimitVar<br>MyObj001.setinfo<br>Set MyObj001=Nothing<br>End Function</p>
<p>使用ASP启动/停止指定WEB站点</p>
<p>程序代码: </p>
<p><br>'======================= |
|