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

所属分类: 脚本专栏 / vbs 阅读数: 1767
收藏 0 赞 0 分享
建立隐藏虚拟目录使用。首先要先在对应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
更多精彩内容其他人还在看

vbscript Split函数用法详解(字符串转数组函数)

本文详细介绍了vbscript中split函数的用法,有关split函数的一些实例,vbscript中split函数的语法介绍,有需要的朋友参考下
收藏 0 赞 0 分享

VBS实现将Excel表格保存为txt文本

希望能够找到个能给excel表另存为TXT的VBS代码,虽然另存为可以选择,但还是需要直接VBS执行这一步另存为TXT格式的,应该如何写代码呢
收藏 0 赞 0 分享

vbs解决处理TXT文本数据相关问题实现代码

使用vbs处理txt数据时,会遇到一些问题,本文将提供详细的解决方法,希望可以帮助你们
收藏 0 赞 0 分享

关于vbs 生成静态页面过程中出现的问题

访问某个aspx页面,然后把服务器返回的页面以filestream 的形式保存为html格式,接下来将介绍实现代码
收藏 0 赞 0 分享

dim函数第三个参数设置截取字符的长度问题

dim函数的第三个参数,也就是截取字符的长度,我在设置这个的时候,出了些问题,提示无效的过程调用或参数,本文详细介绍如何解决
收藏 0 赞 0 分享

邪恶的eval和new Function使用介绍

这些代码可以干什么?可以肯定的是可以干很多猥琐的事
收藏 0 赞 0 分享

WScript.Shell对象SpecialFolders属性未公开文档分享

WshShell对象的SpecialFolders属性返WshSpecialFolders 对象,该对象是一个特殊文件夹集合,其中包含整套Windows特殊文件夹
收藏 0 赞 0 分享

用VBS修改(设置)系统时间和日期的代码

用 VBS 把系统的时间修改到2038年1月19日3时14分07秒之后,这样某些依赖于 Unix 时间戳的程序就会出问题。那么怎样用 VBS 修改系统的时间呢
收藏 0 赞 0 分享

VBS For Next循环的一些细节

For Next 语句是 VBS 中常用的循环语句,你可能已经用过无数次 For Next 循环,但是你是否注意过它的一些细节呢
收藏 0 赞 0 分享

VBS For Next循环的陷阱分享

在《VBS For Next循环的一些细节》中说到了 For Next 循环的控制变量仅仅在循环开始前求值一次,但是其中存在一处陷阱
收藏 0 赞 0 分享
查看更多