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

改进后的mkw3site.vbs(创建虚拟目录)相关推荐

  1. vbs脚本在服务器上虚拟按键,iisvdir.vbs iis虚拟目录管理脚本使用介绍

    IIS管理器也是通过调用iisvdir.vbs来实现虚拟目录的创建和删除的.我们可以通过命令行的方式来执行iisvdir.vbs脚本 1)创建虚拟目录: cscript c:\windows\syst ...

  2. xp创建虚拟服务器,Xp系统怎么创建虚拟目录?Xp系统创建虚拟目录的方法

    Xp系统怎么创建虚拟目录?xp系统是一款非常经典的windows系统,其一直深受着广大用户们的喜爱.虽然目前微软不在支持xp系统了但是使用还是有部分用户选择使用xp系统.下面小编就给大家带来Xp系统创 ...

  3. VS中 无法创建虚拟目录 本地IIS IIS Express 外部主机

    从前就有个疑问了,为什么我拉取别人写好的代码后就可以在IIS里面生成一个网站呢? 这里所谓的生成网站,是指包含了所有源代码文件的网站:相对地,发布网站,就是指包含被编译的源文件所得到的DLL文件的网站 ...

  4. iis5.1安装方法(适用于XP)以及运行调试asp程序,创建虚拟目录【整理】

    Author:张继飞 写在前面:因为要运行asp程序,建立一个小小的网站,呵呵.所以需要安装iis对环境进行安装设置.下面是从网上找到的一些资料,并加上自己的总结,成为一个整篇的方法介绍,为大家寻找一 ...

  5. xp本地服务器虚拟目录创建,WindowsXp系统怎么创建虚拟目录

    xp是一款非常经典的windows系统,其一直深受着广大用户们的喜爱.今天,小编将在这里向大家介绍在WinXp系统中创建虚拟目录的方法,希望帮助大家更好地使用它,感兴趣的朋友可以一起来看看! 什么是虚 ...

  6. VS中 无法创建虚拟目录

    从前就有个疑问了,为什么我拉取别人写好的代码后就可以在IIS里面生成一个网站呢? 这里所谓的生成网站,是指包含了所有源代码文件的网站:相对地,发布网站,就是指包含被编译的源文件所得到的DLL文件的网站 ...

  7. Tomcat应用部署:打war包、在Tomcat中注册用户角色、创建虚拟目录和域名

    #1.打war包 1)命令:jar -cvf xx.war * (备注:执行打包的前提条件:目录必须切换到打包项目的webRoot(webContent)目录下) 备注:1. c:创建新的文档v:显示 ...

  8. XAMPP修改80和443端口及创建虚拟目录

    由于装了IIS,Xampp不能用了.原因是:iis占用了xampp需要的80.443端口.Xampp要修改两个地方才能启动Apache.不然就把模块Mod_SSL注释掉.就可以不用理443这个了. X ...

  9. 创建虚拟目录http://localhost:1780/失败,错误:无法访问iis元数据库。您没用足够的特权访问计算机上的IIS网站...

    使用visual studio 2017 启动项目时,不知道什么原因出现如下错误:导致系统打不开 倒腾一番:最后可以了 总共三步,步骤如下: 1. 在注册表中修改Personal的value:%USE ...

最新文章

  1. 腾讯AI击败王者荣耀职业队,全靠自学、策略清奇,一天训练量为人类440年
  2. SpringBoot 源码解析 (一)----- SpringBoot核心原理入门
  3. 关于synchronize与lock的区别
  4. 批次管理的质量跟踪案例分享_食品加工行业
  5. .adobe.ETH.btc.frendi.AUF.AYE.qwex后缀勒索病毒
  6. 开发小技巧之:unicode的排序和正则匹配
  7. 克服SOA实施过程中的障碍
  8. 选择器高级、样式及布局
  9. MessageDigest(加密)
  10. 555定时器基本原理
  11. 遥感或DEM像素深度如何降为8bit
  12. netty权威指南目录
  13. linux如何做动态壁纸实验报告,Ubuntu制作动态壁纸
  14. java计算时间差_Java中计算两个日期的时间差
  15. processing实现图像碎片化
  16. 阿里巴巴离职DBA职业生涯总结
  17. [YOLOv7/YOLOv5系列算法改进NO.5]改进特征融合网络PANET为BIFPN(更新添加小目标检测层yaml)
  18. Dxf 3d模型素材推荐
  19. 转杨毅:火箭输得有谱了!
  20. 如何用python统计英语文章词频?

热门文章

  1. Spring Cloud Alibaba 大型微服务项目实战
  2. 【医学+深度论文:F19】Integrating holistic and local deep features for glaucoma classification
  3. Imagick和GD图片处理旋转等问题
  4. android 基于ijkplayer项目进行的播放器
  5. 都说产品要懂数据分析,到底要懂到什么程度?(附分析模板)
  6. 应用案例 | 2009 款别克凯越车发动机怠速转速过高故障诊断
  7. scp远程服务器拷贝到远程服务器
  8. 计算机算自然科学还是社会科学,哲学属于自然科学还是社会科学?
  9. 开源自主导航小车MickX4(九)基于move_base 的自主导航框架
  10. Reson7125型多波束的一次故障记录