改进后的mkw3site.vbs(创建虚拟目录)

原创 2003年07月14日 16:18:00

//////////////////////////
作者: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 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

Tomcat设置虚拟目录的方法

tomcat版本:apache-tomcat-7.0.42 参考:http://blog.csdn.net/pangdingshan/article/details/7214786 一、虚拟根...
  • zjml2412
  • zjml2412
  • 2015年11月21日 11:15
  • 8548

使用libvirt创建虚拟机,虚拟机的配置文件内容

libvirt介绍     Libvirt是一个软件集合,便于使用者管理虚拟机和其他虚拟化功能,比如存储和网络接口管理等等。Libvirt概括 起来包括一个API库、一个 daemon(libvi...
  • U201017971
  • U201017971
  • 2016年03月23日 16:04
  • 2138

idea设置tomcat虚拟路径的两种方法

1.使用tomcat自己的虚拟路径 1.1.在tomcat\config\server.xml中配置 path="/upload" 虚拟路径 E:\photo\upload 图片存放的真实路径...
  • Cheney550995353
  • Cheney550995353
  • 2017年04月15日 16:37
  • 2928

iisvdir.vbs管理虚拟目录

虚拟目录的配置简单来说就是创建虚拟目录。用手工的方式实现非常简单,直接设定“Web sharing”就可以了,让我们看看怎么通过编程的方式实现,两种创建虚拟目录的方法:  1、通过调用iisvdir...
  • aking8736
  • aking8736
  • 2011年12月21日 16:43
  • 749

创建虚拟目录方法介绍

  • 2011年08月26日 09:23
  • 313KB
  • 下载

用VB创建IIS虚拟目录

  • 2008年09月15日 02:30
  • 9KB
  • 下载

C# 创建IIS虚拟目录

  • 2011年01月04日 12:23
  • 9KB
  • 下载

IIS 相关概念(站点、虚拟目录、应用程序池、隔离模式、W3WP.EXE、Web Gargen) 及 IIS 6的ASP.net请求处理过程

基本概念:1. 站点程序:在IIS中我们所新建的站点,可以为其配置ASP.net以及应用程序池的版本。2. 虚拟目录:用来将不同的文件夹中的内容通过虚拟目录组织到同一个文件夹中,相当于一个应用程序,也...
  • DavidInternet
  • DavidInternet
  • 2011年03月16日 19:19
  • 1583

配置子目录Web.config使其消除继承,用虚拟目录创建多个网站的方法

配置子目录Web.config使其消除继承,用虚拟目录创建多个网站的方法 by shinichi_wtn 2011-02-20 19:54 ASP.NET提供了强大的Web.config来...
  • PAPALIAN
  • PAPALIAN
  • 2012年01月16日 09:48
  • 14821

如何:在IIS 中创建和配置虚拟目录

http://yxiaoli.2009.blog.163.com/blog/static/12994237320104206320337/ 如何:在IIS 中创建和配置虚拟目录 此页面仅适...
  • mituan1234567
  • mituan1234567
  • 2014年08月12日 13:02
  • 999
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:改进后的mkw3site.vbs(创建虚拟目录)
举报原因:
原因补充:

(最多只允许输入30个字)