目的
用vbs在IIS6上创建多个网站,每个网站有独立的目录,独立的应用程序池
方法
通过adsutil.vbs实现
方式
将要执行的命令写入一个bat文件,然后执行该文件,如此进行多次循环,一次循环建立一个网站
问题
1.执行bat时,如果加上,vbhide参数,则总只会执行最后生成的那个bat,即也只会建立最后的那个网站
所以目前是件cmd命令行放在前台执行,运行时会产生多个cmd窗口,比较难看
2.选用的网站名称也只是1,2,。。。。,N,尝试过试用WebSite_1格式的网站名,但是执行结果不如预期
希望路过的各位有经验人士帮忙看一下这两个问题如何解决,在这里谢谢啦~ :)
Dim str
Dim name,path,port
Dim pool
Dim var0
Dim var1,var2,var3,var4,var5,var6,var7
Dim var8,var9,var10,var11,var12,var13,var14
Dim var15,var16
Add
Sub Add()
Dim counter
Dim LoopTimes
counter = 0
LoopTimes = 10
Do while counter < LoopTimes
counter = counter + 1
'初始化
'网站
name = "w3svc/"
path = "c:/html"
port = 1000
servercomment = ""
'应用程序池
pool = ""
'参数实际值
'网站
name = name&cstr(counter)
'path = path&"/"&cstr(counter)
port = port + counter
servercomment = servercomment&cstr(counter)
'应用程序池
pool = pool&cstr(counter)
'输出确认
'MsgBox "网站名 ["&name&"]["&path&"]["&port&"]["&pool&"]"
var0 = ""
var01 = "mkdir "&path& "/" &cstr(counter)
var02 = "copy " &path& "/index.html " &path& "/" &cstr(counter)
var1 = "adsutil.vbs create_vserv "&name
var2 = "adsutil.vbs set " &name& "/serversize 1"
var3 = "adsutil.vbs set " &name& "/servercomment "&servercomment
var4 = "adsutil.vbs set " &name& "/serverbindings :"&port&":"
var5 = "adsutil.vbs set " &name& "/enabledefaultdoc true"
var6 = "adsutil.vbs create_vdir " &name& "/root "
var7 = "adsutil.vbs set " &name& "/root/path " &path&"/"&cstr(counter)
var8 = "adsutil.vbs set " &name& "/root/accessread true "
var9 = "adsutil.vbs set " &name& "/root/accesswrite true "
var10 = "adsutil.vbs set " &name& "/root/enabledirbrowsing true "
var11 = "adsutil.vbs set " &name& "/root/enabledefaultdoc true "
var12 = "adsutil.vbs set " &name& "/root/accessscript true "
var13 = "adsutil.vbs set " &name& "/root/appfriendlyName 1.html "
var14 = "adsutil.vbs start_server " &name
var15 = "adsutil.vbs create w3svc/AppPools/" &pool& " IIsApplicationPool"
var16 = "adsutil.vbs set w3svc/"&cstr(counter)&"/root/AppPoolId " &pool
'写入文件
DFRecordFileName="C:/Inetpub/AdminScripts/tmp"&cstr(counter)&".bat"
Set myStream=CreateObject("adodb.Stream")
myStream.Type=2
myStream.mode=3
myStream.charset="utf-8"
myStream.open
myStream.writeText var0 & vbcrlf
myStream.writeText var01 & vbcrlf
myStream.writeText var02 & vbcrlf
myStream.writeText var1 & vbcrlf
myStream.writeText var2 & vbcrlf
myStream.writeText var3 & vbcrlf
myStream.writeText var4 & vbcrlf
myStream.writeText var5 & vbcrlf
myStream.writeText var6 & vbcrlf
myStream.writeText var7 & vbcrlf
myStream.writeText var8 & vbcrlf
myStream.writeText var9 & vbcrlf
myStream.writeText var10 & vbcrlf
myStream.writeText var11 & vbcrlf
myStream.writeText var12 & vbcrlf
myStream.writeText var13 & vbcrlf
myStream.writeText var15 & vbcrlf
myStream.writeText var16 & vbcrlf
myStream.writeText var14 & vbcrlf
myStream.saveToFile DFRecordFileName,2
myStream.close
set myStream=nothing
'执行
set ws=Createobject("wscript.shell")
ws.run "tmp"&cstr(counter)&".bat"
Loop
End Sub