首页 > 网站 > IIS > 正文

用VBS创建IIS虚拟站点实例

2024-08-29 03:13:53
字体:
来源:转载
供稿:网友

' ---------------------------------------------------------------------------
' creates or deletes the virtual directory http://localhost/channel7
'
' valid command line switches: -i -u -q
'   -i  install virtual directory
'   -u  remove virtual directory
'   -q  run in quiet mode
'
' ---------------------------------------------------------------------------
' see http://www.microsoft.com/windows2000/en/advanced/iis/default.asp?url=/windows2000/en/advanced/iis/htm/asp/aore8v5e.htm

option explicit

dim vpath,vname, vwshshell, vobjargs, vinstall, vremove, vquiet, i

vname = "channel7"

' get current path to folder
vpath = left(wscript.scriptfullname, instrrev(wscript.scriptfullname, "/", 15) - 1)
vpath = vpath & "/owbase"

'set wshshell = wscript.createobject("wscript.shell")
'vpath = wshshell.regread("hklm/software/channel7") & "/owbase"

vquiet = false
vinstall = false
vremove = false

set vobjargs = wscript.arguments

for i = 0 to vobjargs.count - 1
    if instr(lcase(vobjargs(i)), "i") <> 0 then
        vinstall = true
    elseif instr(lcase(vobjargs(i)), "u") <> 0 then
        vremove = true
    end if
    if instr(lcase(vobjargs(i)), "q") <> 0 then
        vquiet = true
    end if
next

if vremove then
    deletevdir vname
elseif vinstall then
    createvdir vname, vpath
end if


sub createvdir(pname, ppath)
    dim vroot, vbasedir, vwebsite, ipsecurityobj, iplist

    on error resume next

    ' get the local host default web
    set vwebsite = getobject("iis://localhost/w3svc/1")
    if not isobject(vwebsite) then
        display "unable to locate the default web site. iis must be installed and running."
        exit sub
    else
        'display vwebsite.name
    end if

    ' get the root
    set vroot = vwebsite.getobject("iiswebvirtualdir", "root")
    if (err <> 0) then
        display "unable to access root for " & vwebsite.adspath
        exit sub
    else
        'display vroot.name
    end if

    ' find or create the ow vroot.
    ' the physical path to http://localhost/ow is set to the ...<install-dir>/owbase folder
    err.number = 0 'clear error
    set vbasedir = getobject(vroot.adspath & "/" + pname)
    if err.number <> 0 then
        err.number = 0
        set vbasedir = vroot.create("iiswebvirtualdir", pname)
        vbasedir.accessread = true
        vbasedir.accessflags = 513  ' = 0x200 + 0x01 = md_access_script + md_access_read
        vbasedir.appcreate false
        vbasedir.aspallowsessionstate = false
        vbasedir.setinfo ' this section restricts access to everyone except localhost (127.0.0.1).
        'set ipsecurityobj = vbasedir.ipsecurity
        'ipsecurityobj.grantbydefault = false
        'iplist = ipsecurityobj.ipgrant
        'redim iplist(ubound(iplist) + 1)
        'iplist(ubound(iplist)) = "127.0.0.1"
        'ipsecurityobj.ipgrant = iplist
        'vbasedir.ipsecurity = ipsecurityobj
        'vbasedir.setinfo

        vbasedir.path = ppath
        vbasedir.appfriendlyname = "channel7"
        vbasedir.setinfo

        if (err <> 0) then
            display "un

|||,欢迎访问网页设计爱好者web开发。able to create " & vroot.adspath & "/" & pname
            exit sub
        else
            err = 0
            'display vbasedir.name
        end if
    end if

end sub


sub deletevdir(pname)
    dim vroot, vbasedir, vwebsite, ipsecurityobj, iplist
    on error resume next

    ' get the local host default web
    set vwebsite = getobject("iis://localhost/w3svc/1")
    if not isobject(vwebsite) then
        display "unable to locate the default web site. iis must be installed and running."
        exit sub
    else
        'display vwebsite.name
    end if

    ' get the root
    set vroot = vwebsite.getobject("iiswebvirtualdir", "root")
    if (err <> 0) then
        display "unable to access root for " & vwebsite.adspath
        exit sub
    else
        'display vroot.name
    end if

    err.number = 0 'clear error
    set vbasedir = getobject(vroot.adspath)

    vbasedir.delete "iiswebvirtualdir", pname
    vbasedir.setinfo

    if not vquiet then
        wscript.echo "virtual directory http://localhost/" & vbasedir.name & "/" & pname & " deleted successfully."
    end if
end sub


sub display(pmsg)
    if not vquiet then
        wscript.echo now & ". error code: " & hex(err) & " - " & pmsg
    end if
end sub

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表