- '---------------------------------------------------------------------------------------------------
- ' 创建虚拟目录 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 doesn't 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 "Couldn't 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 "Couldn't 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
改进后的mkw3site.vbs(创建虚拟目录)
2020-07-09 09:34VBS代码网 VBS
本文主要讲解使用vbs代码创建虚拟目录的方法,如果您需要设置权限,请修改40-56 的代码。
延伸 · 阅读
- 2022-02-16Apache虚拟目录配置及vue-cli反向代理的设置方法
- 2021-12-09禁用VBS提高Windows 11性能,这个技巧必须要掌握
- 2021-12-01Apache配置虚拟目录和多主机头的方法
- 2021-12-01Asp.Net Core 中的“虚拟目录”实现
- 2021-11-13使用VBS创建快捷方式的代码
- 2021-11-13如何使用vbs 监控电脑活动记录
精彩推荐
- VBS
提供个可以显示农历的VBS代码
本文主要分享一段可以显示农历的VBS代码,具有一定的参考价值,有需要的朋友可以了解一下...
- VBS
VBS教程:正则表达式简介 -建立正则表达式
建立正则表达式 构造正则表达式的方法和创建数学表达式的方法一样。也就是用多种元字符与操作符将小的表达式结合在一起来创建更大的表达式。 可以...
- VBS
可以定时自动关机的vbs脚本
这篇文章主要分享一段可以定时自动关机的vbs脚本代码,有需要的童鞋可以学习下...
- VBS
VBS教程:对象-Folders 集合
VBS教程:对象-Folders 集合...
- VBS
脚本 MsAgent组件 微软精灵 揪出系统自带的宠物
你知道系统里有一个隐藏的宠物吗? 将以下代码保存为后缀为.vbs的文件,再双击运行,看看出来什么?一个可爱的魔法老人!还会说话、移动、吹喇叭…...
- VBS
VBS教程:属性-AvailableSpace 属性
VBS教程:属性-AvailableSpace 属性 ...
- VBS
vbs base64 解密脚本代码
解密base64的vbs小函数,支持英文与数字不支持中文。...
- VBS
VBS教程:属性-VolumeName 属性
VBS教程:属性-VolumeName 属性...