转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> VB.NET程序 >> 正文
改进后的mkw3site.vbs(创建虚拟目录)         ★★★★

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

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1767 更新时间:2009/4/23 18:59:34

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

[1] [2]  下一页


[VB.NET程序]把VB的程序写成VBScript方式放在VBS文件中  [VB.NET程序]世界第一等-----无须安装WSH而执行VBS
[VB.NET程序]蛙蛙推荐:VBS的数据库操作类,  [VB.NET程序]实现E-mail地址验证的vbs函数代码
[VB.NET程序]VBS 中 Space 函数的应用  [VB.NET程序]目录浏览,目录在左,文件在右(VBS)
[VB.NET程序]一句话木马用upfile.vbs  [VB.NET程序]如何修复:Windows上面的WScript的脚本(.vbs)不能…
[VB.NET程序]一道面试题, 求 1000!的位数(VBS实现)  [网页制作]Top Site From CHP - 精彩截图
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台