IISのスクリプトで設定

ADSUtil.vbs を使って例


//仮想フォルダ作成
cscript adsutil.vbs CREATE W3SVC/1/Root/MyDir "IIsWebVirtualDir"
//ローカルパス作成
cscript adsutil.vbs SET W3SVC/1/Root/MyDir/Path "d:\xxx\"
//保護(中)の設定
cscript adsutil.vbs APPCREATEPOOLPROC W3SVC/1/Root/MyDir

ChangeProperties_ADSI.js を使った設定
以下のファイルを作成します。文字の間はtab文字(\t)にします。


LocalHost w3svc ConnectionTimeout 999
LocalHost w3svc/1/root/MyDir Path d:\xxxx\
LocalHost w3svc/1/root/MyDir AccessWrite TRUE
LocalHost w3svc/1/root/MyDir AppFriendlyName MyDir
LocalHost w3svc/1/root/MyDir ScriptMaps .htm,C:\WINDOWS\System32\inetsrv\Test.dll,5,
LocalHost w3svc/1/root/MyDir ContentIndexed FALSE
LocalHost w3svc/1/root/MyDir HttpCustomHeaders Cache-Control,private
コマンドプロンプトから以下を実行
cscript /nologo changeproperties_adsi.js (上のファイル名指定)

IIS6.0 にてアプリケーションプールを作成するVBSを作りました。
動作確認とかほとんどしていないので、参考程度と思ってください。
VBS もネットで検索しながら何とかはじめて書いてみました。


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


Dim IIsWebAppPoolRoolObj
Dim IIsWebAppPoolObj
Dim IIsWebAppObj

Dim ObjectPath
Dim ObjectParameter
Dim MachineName
Dim ValueList


' 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

'*****************************************************
' Modified by Matt Nicholson
Dim TargetServer 'The server to be examined/modified
Dim I
For I = 0 To ArgObj.Count - 1
If LCase(Left(ArgObj.Item(I), 3)) = "-s:" Then
TargetServer = Right(ArgObj.Item(I), Len(ArgObj.Item(I)) - 3)
Else
Args(ArgCount) = ArgObj.Item(I)
ArgCount = ArgCount + 1
End If
Next
If Len(TargetServer) = 0 Then
TargetServer = "localhost"
End If
'*****************************************************

ObjectPath = Args(0)
SanitizePath ObjectPath
MachineName = TargetServer
ObjectParameter = SplitParam(ObjectPath)

ValueList = Args(1)


'アプリケーションプールの作成
Set IIsWebAppPoolRoolObj = GetObject("IIS://" & MachineName & "/W3SVC/AppPools")
Set IIsWebAppPoolObj = IIsWebAppPoolRoolObj.Create("IIsApplicationPool", ValueList)

'Webアプリを作成したプールへ設定
Set IIsWebAppObj = GetObject("IIS://" & MachineName & "/" & ObjectPath & "/" & ObjectParameter)
IIsWebAppObj.put "AppPoolId", ValueList

'コミット
IIsWebAppPoolObj.SetInfo
IIsWebAppObj.SetInfo

WScript.Quit ()


''''''''''''''''''''''''''''
'
' Display Help Message
'
''''''''''''''''''''''''''''
Sub DisplayHelpMessage()
WScript.Echo
WScript.Echo "Samples:"
WScript.Echo " apppool.vbs W3SVC/1/Root/MyDir AppPoolTest"


End Sub


Sub SanitizePath(ObjectPath)
On Error Resume Next

' Remove WhiteSpace
Do While (Left(ObjectPath, 1) = " ")
ObjectPath = Right(ObjectPath, Len(ObjectPath) - 1)
Loop

Do While (Right(ObjectPath, 1) = " ")
ObjectPath = Left(ObjectPath, Len(ObjectPath) - 1)
Loop

' Replace all occurrences of \ with /
ObjectPath = Replace(ObjectPath, "\", "/")

' Remove leading and trailing slashes
If Left(ObjectPath, 1) = "/" Then
ObjectPath = Right(ObjectPath, Len(ObjectPath) - 1)
End If

If Right(ObjectPath, 1) = "/" Then
ObjectPath = Left(ObjectPath, Len(ObjectPath) - 1)
End If

If (Err.Number <> 0) Then
ReportError ()
WScript.Echo "Error Trying To Sanitize the path: " & ObjectPath
WScript.Quit (Err.Number)
End If

End Sub

Function SplitParam(ObjectPath)
' Note: Assume the string has been sanitized (no leading or trailing slashes)
On Error Resume Next

Dim SlashIndex
Dim TempParam
Dim ObjectPathLen

SplitParam = "" ' Assume no parameter
ObjectPathLen = Len(ObjectPath)

' Separate the path of the node from the parameter
SlashIndex = InStrRev(ObjectPath, "/")

If (SlashIndex = 0) Or (SlashIndex = ObjectPathLen) Then
TempParam = ObjectPath
ObjectPath = "" ' ObjectParameter is more important
Else
TempParam = ObjectPath
ObjectPath = Left(ObjectPath, SlashIndex - 1)
TempParam = Right(TempParam, Len(TempParam) - SlashIndex)
End If

SplitParam = TempParam

If (Err.Number <> 0) Then
ReportError ()
WScript.Echo "Error trying to Split the parameter from the object: " & ObjectPath
WScript.Quit (Err.Number)
End If

End Function