使用ASP在IIS创建WEB站点的函数

论坛 期权论坛     
niminba   2021-5-22 16:48   113   0
<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://" &amp; Computer &amp; "/w3svc")<br>If Err.Number &lt;&gt; 0 Then '显示错误提示<br>&nbsp;response.write "无法打开: "&amp;"IIS://" &amp; Computer &amp; "/w3svc"<br>&nbsp;response.end<br>End If<br>'检测是否有设定相同IP地址、端口及主机名的站点存在<br>BindingString = IPAddr &amp; ":" &amp; PortNum &amp; ":" &amp; HostName<br>For Each WebServer in w3svc<br>&nbsp;If WebServer.Class = "IIsWebServer" Then<br>&nbsp;Bindings = WebServer.ServerBindings<br>&nbsp;If BindingString = Bindings(0) Then<br>&nbsp;response.write "IP地址冲突:" &amp; IPAddr &amp; ",请检测IP地址!."<br>&nbsp;Exit Function<br>&nbsp;End If<br>&nbsp;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://"&amp;Computer&amp;"/w3svc/"&amp;SiteNum) '加载指定站点<br>If (Err.Number = 0) Then<br>&nbsp;'response.write " Step_1站点"&amp;SiteNum&amp;"存在"<br>&nbsp;SiteNum = SiteNum + 1<br>Else<br>&nbsp;'response.write " Step_1站点"&amp;SiteNum&amp;"不存在"<br>&nbsp;Err.Clear<br>&nbsp;Set NewWebServer = w3svc.Create("IIsWebServer",SiteNum) '创建指定站点<br>&nbsp;If (Err.Number &lt;&gt; 0) Then<br>&nbsp;'response.write " Step_2站点"&amp;SiteNum&amp;"创建失败"<br>&nbsp;SiteNum = SiteNum + 1<br>&nbsp;Else<br>&nbsp;'response.write " Step_2站点"&amp;SiteNum&amp;"创建成功"<br>&nbsp;bDone = True<br>&nbsp;End If<br>End If<br>If (SiteNum &gt; 50) Then '服务器最大创建站点数<br>&nbsp;response.write "超出服务器最大创建站点数,正在创建的站点的序号为: "&amp;SiteNum&amp;"."<br>&nbsp;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 = "应用程序" &amp; WebSiteInfo<br>NewDir.AppCreate True<br>NewDir.AccessScript = True<br>Err.Clear<br>NewDir.SetInfo<br>If (Err.Number &lt;&gt; 0) Then<br>&nbsp;response.write "主目录创建时出错."<br>&nbsp;response.end<br>End If<br>If StartOrStop = True Then<br>&nbsp;Err.Clear<br>&nbsp;Set NewWebServer = GetObject("IIS://" &amp; Computer &amp; "/w3svc/" &amp; SiteNum)<br>&nbsp;NewWebServer.Start<br>&nbsp;If Err.Number &lt;&gt; 0 Then<br>&nbsp;response.write "启动站点时出错!"<br>&nbsp;response.end<br>&nbsp;Err.Clear<br>&nbsp;End If<br>End If<br>response.write "站点创建成功,站点编号为:"&amp; SiteNum &amp;" ,域名为:"&amp; 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://"&amp;Computer&amp;"/W3SVC/"&amp;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>'=======================
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1060120
帖子:212021
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP