IIS設定VBスクリプト

IISのMAPSを設定するVBスクリプトを作成してみた。リスト型で複数設定できる。
ファイルを事前に作成しておく必要がある。こんな感じで。先頭行は仮想フォルダ名。

          • -

W3SVC/1/Root/xxxx
.asax,C:\Windows\\xxxx\aspnet_isapi.dll,5,"GET,HEAD,POST"
.asmx,C:\Windows\\xxxx\aspnet_isapi.dll,5,"GET,HEAD,POST"
.config,C:\Windows\\xxxx\aspnet_isapi.dll,1,"GET,HEAD,POST"

          • -


Dim ArgObj ' Object which contains the command line argument
Dim Result ' Result of the command function call
Dim Args(10) ' Array that contains all of the non-global arguments
Dim ArgCount ' Tracks the size of the Args array

ReDim Maps(0)
Dim ObjectPath
Dim fName

' Get the Arguments object
Set ArgObj = WScript.Arguments

' Test to make sure there is at least one command line arg - the command
If ArgObj.Count < 1 Then
DisplayHelpMessage
WScript.Quit (GENERAL_FAILURE)
End If

Dim I
For I = 0 To ArgObj.Count - 1
Args(ArgCount) = ArgObj.Item(I)
ArgCount = ArgCount + 1
Next

fName = Args(0)
Const ForReading = 1
Const TristateFalse = 0
Dim retstring
Dim fs, f
Dim iLine
iLine = 0

Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(fName) <> True then
WScript.Echo fName & " File not Found"
WScript.Quit ()
End If
Set f = fs.OpenTextFile(fName, ForReading, TristateFalse)
Do While f.AtEndOfStream <> True
iLine = iLine + 1
retstring = f.ReadLine
If iLine = 1 then
ObjectPath = retstring
Else
ReDim Preserve Maps(iLine - 2)
Maps(iLine - 2) = retstring
End If
Loop
f.Close

Set IIsWebAppObj = GetObject("IIS://localhost/" & ObjectPath)

'全部削除する
IIsWebAppObj.PutEx 1, "ScriptMaps", True
'Mapsを設定
IIsWebAppObj.PutEx 2, "ScriptMaps", Maps

IIsWebAppObj.SetInfo

WScript.Quit ()

Sub DisplayHelpMessage()

WScript.Echo " IISMap_ADSI.vbs"
WScript.Echo " "
WScript.Echo " "
WScript.Echo " \t Syntax:"
WScript.Echo " IISMap.js "
WScript.Echo " "
WScript.Echo " \t Example:"
WScript.Echo " Cscript /nologo IISMap_ADSI.js c:\\mymaps.txt"
WScript.Echo " "
WScript.Echo " \t Syntax of File:"
WScript.Echo " "
WScript.Echo " "
WScript.Echo " "
WScript.Echo " \t Example of File:"
WScript.Echo " w3svc/1/Root/xxx"
WScript.Echo " .htm,C:\WINDOWS\System32\inetsrv\Test.dll,5,GET, HEAD, POST"
WScript.Echo " .aspx,C:\WINDOWS\System32\inetsrv\Test.dll,5,GET, HEAD, POST"
WScript.Echo " "
WScript.Echo " "

End Sub


IISのCustomHeaderを設定するVBスクリプトを作成してみた。リスト型で複数設定できる。
ファイルを事前に作成しておく必要がある。こんな感じで。先頭行は仮想フォルダ名。

        • -

W3SVC/1/Root/xxxx
X-Powered-By:ASP.NET
Cache-Control:private

        • -


Dim ArgObj ' Object which contains the command line argument
Dim Result ' Result of the command function call
Dim Args(10) ' Array that contains all of the non-global arguments
Dim ArgCount ' Tracks the size of the Args array

ReDim Maps(0)
Dim ObjectPath
Dim fName

' Get the Arguments object
Set ArgObj = WScript.Arguments

' Test to make sure there is at least one command line arg - the command
If ArgObj.Count < 1 Then
DisplayHelpMessage
WScript.Quit (GENERAL_FAILURE)
End If

Dim I
For I = 0 To ArgObj.Count - 1
Args(ArgCount) = ArgObj.Item(I)
ArgCount = ArgCount + 1
Next

fName = Args(0)
Const ForReading = 1
Const TristateFalse = 0
Dim retstring
Dim fs, f
Dim iLine
iLine = 0

Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(fName) <> True then
WScript.Echo fName & " File not Found"
WScript.Quit ()
End If
Set f = fs.OpenTextFile(fName, ForReading, TristateFalse)
Do While f.AtEndOfStream <> True
iLine = iLine + 1
retstring = f.ReadLine
If iLine = 1 then
ObjectPath = retstring
Else
ReDim Preserve Maps(iLine - 2)
Maps(iLine - 2) = retstring
End If
Loop
f.Close

Set IIsWebAppObj = GetObject("IIS://localhost/" & ObjectPath)

'全部削除する
IIsWebAppObj.PutEx 1, "HttpCustomHeaders", True
'Mapsを設定
IIsWebAppObj.PutEx 2, "HttpCustomHeaders", Maps

IIsWebAppObj.SetInfo

WScript.Quit ()

Sub DisplayHelpMessage()

WScript.Echo " IISMap_ADSI.vbs"
WScript.Echo " "
WScript.Echo " "
WScript.Echo " \t Syntax:"
WScript.Echo " IISMap.js "
WScript.Echo " "
WScript.Echo " \t Example:"
WScript.Echo " Cscript /nologo CusHead_ADSI.js c:\\myhead.txt"
WScript.Echo " "
WScript.Echo " \t Syntax of File:"
WScript.Echo " "
WScript.Echo " "
WScript.Echo " "
WScript.Echo " \t Example of File:"
WScript.Echo " w3svc/1/Root/xxx"
WScript.Echo " X-PoeredBy,ASP.NET"
WScript.Echo " "
WScript.Echo " "

End Sub