使用ASP在IIS创建WEB站点的函数
程序员文章站
2023-10-20 13:36:00
============================================================= '  ...
=============================================================
' 感谢您使用asp001工作室开发的实用函数程序
' http://www.asp001.net
'=============================================================
'asp001工作室为您提供订制程序开发、企业互联网拓展服务
'qq:1974229
'e-mail:shenyangchuqi@tom.com
'更多程序下载请到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
' 感谢您使用asp001工作室开发的实用函数程序
' http://www.asp001.net
'=============================================================
'asp001工作室为您提供订制程序开发、企业互联网拓展服务
'qq:1974229
'e-mail:shenyangchuqi@tom.com
'更多程序下载请到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
推荐阅读
-
使用ASP在IIS创建WEB站点的函数
-
使用ASP在IIS创建WEB站点的函数
-
[ASP.NET]如何使用类创建公共函数,在不同ASP.NET页面间重复调用
-
在ASP.NET Core中创建内部使用Scoped服务的Quartz.NET宿主服务
-
使用 ASP.NET Core MVC 创建 Web API——响应数据的内容协商(七)
-
在 Azure 中的 Windows 虚拟机上使用 SSL 证书保护 IIS Web 服务器
-
创建使用BPEL业务流程的WEB站点 WebStrutsWebsphereJSP应用服务器
-
如何使用ASP.NET Core、EF Core、ABP(ASP.NET Boilerplate)创建分层的Web应用程序(第一部分)
-
在云服务器上使用iis搭建一个ftp站点的方法图解
-
在ASP.Net Web Forms中使用依赖注入的步骤