溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

改進后的mkw3site.vbs有什么用

發(fā)布時間:2021-10-13 15:06:44 來源:億速云 閱讀:155 作者:小新 欄目:開發(fā)技術(shù)

這篇文章給大家分享的是有關(guān)改進后的mkw3site.vbs有什么用的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

 
'---------------------------------------------------------------------------------------------------
' 創(chuàng)建虛擬目錄  POWER BY JARON , 江都資訊網(wǎng) , 1999-2002. 
' 如果您需要設(shè)置權(quán)限,請修改40-56 的代碼。 ** 根據(jù) 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
' 設(shè)置可寫、腳本執(zhí)行權(quán)限
Dim prop(15,2)
Dim propNum
prop(propNum,0) = "AccessRead"
prop(propNum,1) = true' 可讀設(shè)為TRUE,不可讀設(shè)為FALSE
propNum = propNum + 1
prop(propNum, 0) = "AccessWrite"
prop(propNum, 1) = true ' 可寫設(shè)為TRUE,不可寫設(shè)為FALSE
propNum = propNum + 1
prop(propNum, 0) = "AccessScript"
prop(propNum, 1) = true ' 可運行腳本文件設(shè)為TRUE,不可運行腳本文件設(shè)為FALSE
propNum = propNum + 1
prop(propNum, 0) = "AccessExecute"
prop(propNum, 1) = false ' 可運行執(zhí)行文件設(shè)為TRUE,不可運行執(zhí)行文件設(shè)為FALSE
propNum = propNum + 1
prop(propNum, 0) = "EnableDirBrowsing"
prop(propNum, 1) = true ' 允許列出目錄設(shè)為TRUE,不允許列出目錄設(shè)為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

感謝各位的閱讀!關(guān)于“改進后的mkw3site.vbs有什么用”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI