欢迎光临
我们一直在努力

改进后的mkw3site.vbs(创建虚拟目录)-ASP教程,系统相关

建站超值云服务器,限时71元/月

//////////////////////////

作者:jaron, 江都资讯网

邮件:jaron@jdinfo.net

网址:http://www.jiangdu.net

本文首次发表于 jiangdu.net ,如果您要转载该文章,请注明出处。

//////////////////////////

—————————————————————————————————

创建虚拟目录 power by jaron , 江都资讯网 , 1999-2002.

如果您需要设置权限,请修改40-56 的代码。 ** 根据 microsoft corp. 的 adminscripts 改写

用法: mkw3site <–rootdirectory|-r root directory>

<–comment|-t server comment>

[–computer|-c computer1[,computer2…]]

[–hostname|-h host name]

[–port|-o port num]

[–ipaddress|-i ip address]

[–sitenumber|-n sitenumber]

[–dontstart]

[–verbose|-v]

[–help|-?]

ip address the ip address to assign to the new server. optional.

host name the host name of the web site for host headers.

warning: only use host name if dns is set up find the server.

port num the port to which the server should bind

root directory full path to the root directory for the new server.

server comment the server comment — this is the name that appers in the mmc.

sitenumberthe site number is the number in the path that the web server

will be created at. i.e. w3svc/3

example 1: mkw3site -r d:\roots\company11 –dontstart -t "my company site"

example 2: mkw3site -r c:\inetpub\wwwroot -t test -o 8080

————————————————————————————————

force explicit declaration of all variables

option explicit

on error resume next

dim argipaddress, argrootdirectory, argservercomment, argskeletaldir, arghostname, argport

dim argcomputers, argstart

dim argsitenumber

dim oargs, argnum

dim verbose

设置可写、脚本执行权限

dim prop(15,2)

dim propnum

prop(propnum,0) = "accessread"

prop(propnum,1) = true 可读设为true,不可读设为false

propnum = propnum + 1

prop(propnum, 0) = "accesswrite"

prop(propnum, 1) = true 可写设为true,不可写设为false

propnum = propnum + 1

prop(propnum, 0) = "accessscript"

prop(propnum, 1) = true 可运行脚本文件设为true,不可运行脚本文件设为false

propnum = propnum + 1

prop(propnum, 0) = "accessexecute"

prop(propnum, 1) = false 可运行执行文件设为true,不可运行执行文件设为false

propnum = propnum + 1

prop(propnum, 0) = "enabledirbrowsing"

prop(propnum, 1) = true 允许列出目录设为true,不允许列出目录设为false

propnum = propnum + 1

argipaddress = ""

arghostname = ""

argport = 80

argstart = true

argcomputers = array(1)

argcomputers(0) = "localhost"

argsitenumber = 0

verbose = false

set oargs = wscript.arguments

argnum = 0

while argnum < oargs.count

select case lcase(oargs(argnum))

case "–port","-o":

argnum = argnum + 1

argport = oargs(argnum)

case "–ipaddress","-i":

argnum = argnum + 1

argipaddress = oargs(argnum)

case "–rootdirectory","-r":

argnum = argnum + 1

argrootdirectory = oargs(argnum)

case "–comment","-t":

argnum = argnum + 1

argservercomment = oargs(argnum)

case "–hostname","-h":

argnum = argnum + 1

arghostname = oargs(argnum)

case "–computer","-c":

argnum = argnum + 1

argcomputers = split(oargs(argnum), ",", -1)

case "–sitenumber","-n":

argnum = argnum + 1

argsitenumber = clng(oargs(argnum))

case "–dontstart":

argstart = false

case "–help","-?":

call displayusage

case "–verbose", "-v":

verbose = true

case else:

wscript.echo "unknown argument "& oargs(argnum)

call displayusage

end select

argnum = argnum + 1

wend

if (argrootdirectory = "") or (argservercomment = "") then

if (argrootdirectory = "") then

wscript.echo "missing root directory"

else

wscript.echo "missing server comment"

end if

call displayusage

wscript.quit(1)

end if

call astcreatewebsite(argipaddress, argrootdirectory, argservercomment, arghostname, argport, argcomputers, argstart)

sub astcreatewebsite(ipaddress, rootdirectory, servercomment, hostname, portnum, computers, start)

dim w3svc, webserver, newwebserver, newdir, bindings, bindingstring, newbindings, computerindex, index, siteobj, bdone

dim comp

on error resume next

for computerindex = 0 to ubound(computers)

comp = computers(computerindex)

if computerindex <> ubound(computers) then

trace "creating web site on " & comp & "."

end if

grab the web service object

err.clear

set w3svc = getobject("iis://" & comp & "/w3svc")

if err.number <> 0 then

display "unable to open: "&"iis://" & comp & "/w3svc"

end if

bindingstring = ipaddress & ":" & portnum & ":" & hostname

trace "making sure this web server doesnt conflict with another…"

for each webserver in w3svc

if webserver.class = "iiswebserver" then

bindings = webserver.serverbindings

if bindingstring = bindings(0) then

trace "the server bindings you specified are duplicated in another virtual web server."

wscript.quit (1)

end if

end if

next

index = 1

bdone = false

trace "creating new web server…"

if the user specified a sitenumber, then use that. otherwise,

test successive numbers under w3svc until an unoccupied slot is found

if argsitenumber <> 0 then

set newwebserver = w3svc.create("iiswebserver", argsitenumber)

newwebserver.setinfo

if (err.number <> 0) then

wscript.echo "couldnt create a web site with the specified number: " & argsitenumber

wscript.quit (1)

else

err.clear

verify that the newly created site can be retrieved

set siteobj = getobject("iis://"&comp&"/w3svc/" & argsitenumber)

if (err.number = 0) then

bdone = true

trace "web server created. path is – "&"iis://"&comp&"/w3svc/" & argsitenumber

else

wscript.echo "couldnt create a web site with the specified number: " & argsitenumber

wscript.quit (1)

end if

end if

else

while (not bdone)

err.clear

set siteobj = getobject("iis://"&comp&"/w3svc/" & index)

if (err.number = 0) then

a web server is already defined at this position so increment

index = index + 1

else

err.clear

set newwebserver = w3svc.create("iiswebserver", index)

newwebserver.setinfo

if (err.number <> 0) then

if call to create failed then try the next number

index = index + 1

else

err.clear

verify that the newly created site can be retrieved

set siteobj = getobject("iis://"&comp&"/w3svc/" & index)

if (err.number = 0) then

bdone = true

trace "web server created. path is – "&"iis://"&comp&"/w3svc/" & index

else

index = index + 1

end if

end if

end if

sanity check

if (index > 10000) then

trace "seem to be unable to create new web server. server number is "&index&"."

wscript.quit (1)

end if

wend

end if

newbindings = array(0)

newbindings(0) = bindingstring

newwebserver.serverbindings = newbindings

newwebserver.servercomment = servercomment

newwebserver.setinfo

now create the root directory object.

trace "setting the home directory…"

set newdir = newwebserver.create("iiswebvirtualdir", "root")

newdir.path = rootdirectory

newdir.accessread = true

err.clear

newdir.setinfo

newdir.appcreate (true)

if (err.number = 0) then

trace "home directory set."

else

display "error setting home directory."

end if

trace "web site created!"

if start = true then

trace "attempting to start new web server…"

err.clear

set newwebserver = getobject("iis://" & comp & "/w3svc/" & index)

newwebserver.start

if err.number <> 0 then

display "error starting web server!"

err.clear

else

trace "web server started succesfully!"

end if

end if

next

call astsetperms(comp, index,argrootdirectory , prop, propnum)

end sub

sub astsetperms(comp, argsitenumber,argrootdirectory , proplist, propcount)

on error resume next

dim oadmin

dim fullpath

fullpath = "iis://"&comp&"/w3svc/" & argsitenumber & "/root"

trace "opening path " & fullpath

set oadmin = getobject(fullpath)

if err.number <> 0 then

display error_nonode

wscript.quit (1)

end if

dim name, val

if propcount > 0 then

dim i

for i = 0 to propcount-1

name = proplist(i,0)

val = proplist(i,1)

if verbose = true then

trace "setting "&fullpath&"/"&name&" = "& val

end if

oadmin.put name, (val)

if err <> 0 then

display "unable to set property "&name

end if

next

oadmin.setinfo

if err <> 0 then

display "不能保存更新信息."

end if

end if

end sub

display the usage message

sub displayusage

wscript.quit (1)

end sub

sub display(msg)

wscript.echo now & ". error code: " & hex(err) & " – " & msg

end sub

sub trace(msg)

if verbose = true then

wscript.echo now & " : " & msg

end if

end sub

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 改进后的mkw3site.vbs(创建虚拟目录)-ASP教程,系统相关
分享到: 更多 (0)

相关推荐

  • 暂无文章