VBScript : IIS7 の 仮想ディレクトリ登録

  Microsoft のドキュメント



IIS7.0 コンフィギュレーション リファレンス

肝心のオブジェクトのリファレンスをみつける事ができませんでしたが、やりたいのは仮想ディレクトリの登録と、
PHP 等の CGI の登録なので、これだけ使えればいいでしょう





  少し使ってみた、オブジェクト的扱いのIIS6との違い



Iis7

基本的には同じなんでしょうが、どちらも元々サンプル等が少なくて解りにくいんで、
提供されてサンプルを見る限りにおいて、IIS7 では、アプリケーション = デフォルトの仮想ディレクトリ
という設定を基本として、アプリケーション内部に別の物理ディレクトリをマップしていく感じです。

アプリケーション無しで仮想ディレクトリのみで設定できるようですが、サンプルから
その設定を作れなかったので、どちらかと言えば正統派の設定になっています。

アプリケーションに設定した情報は下位にひきつがれるのでこれでいいでしょう。



  ソースコード

2回実行できません。存在チェックはできそうですが、削除は GUI からするほうが良いでしょう

  
' 初期処理
Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set sitesSection = adminManager.GetAdminSection( _
	"system.applicationHost/sites", _
	"MACHINE/WEBROOT/APPHOST" _
)

' サイト内より特定のサイトを決定
Set sitesCollection = sitesSection.Collection
siteElementPos = FindElement(sitesCollection, "site", Array("name", "Default Web Site"))

If (siteElementPos = -1) Then
   WScript.Echo "Element not found!"
   WScript.Quit
End If

' Default Web Site
Set siteElement = sitesCollection.Item(siteElementPos)
Set siteCollection = siteElement.Collection

' アプリケーション追加
Set applicationElement = siteCollection.CreateNewElement("application")
applicationElement.Properties.Item("path").Value = "/lightbox"
Set applicationCollection = applicationElement.Collection


' 一つ目の仮想ディレクトリ( デフォルト )
Set virtualDirectoryElement = applicationCollection.CreateNewElement("virtualDirectory")
virtualDirectoryElement.Properties.Item("path").Value = "/"
virtualDirectoryElement.Properties.Item("physicalPath").Value = "C:\user\lightbox"
applicationCollection.AddElement(virtualDirectoryElement)

' 二つ目の仮想ディレクトリ
Set virtualDirectoryElement2 = applicationCollection.CreateNewElement("virtualDirectory")
virtualDirectoryElement2.Properties.Item("path").Value = "/TMP"
virtualDirectoryElement2.Properties.Item("physicalPath").Value = "C:\user\TMP"
applicationCollection.AddElement(virtualDirectoryElement2)
siteCollection.AddElement(applicationElement)

' lightbox(アプリケーション)に php 設定
Set handlersSection = adminManager.GetAdminSection( _
	"system.webServer/handlers", _
	"MACHINE/WEBROOT/APPHOST/Default Web Site/lightbox" _
)
Set handlersCollection = handlersSection.Collection
Set addElement = handlersCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "PHP-FastCGI"
addElement.Properties.Item("path").Value = "*.php"
addElement.Properties.Item("verb").Value = "GET,HEAD,POST"
addElement.Properties.Item("modules").Value = "FastCgiModule"
addElement.Properties.Item("scriptProcessor").Value = "C:\php-5.2.8-Win32\php-cgi.exe"
addElement.Properties.Item("resourceType").Value = "Unspecified"
addElement.Properties.Item("requireAccess").Value = "Script"
Call handlersCollection.AddElement(addElement, 0)

adminManager.CommitChanges()

' ディレクトリ参照を有効にする
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site/lightbox"

Set directoryBrowseSection = adminManager.GetAdminSection( _
	"system.webServer/directoryBrowse", _
	"MACHINE/WEBROOT/APPHOST/Default Web Site/lightbox" _
)
directoryBrowseSection.Properties.Item("enabled").Value = True
directoryBrowseSection.Properties.Item("showFlags").Value = "Date, Time, Size, Extension"

adminManager.CommitChanges()


' Microsoft のサンプルのまま
Function FindElement(collection, elementTagName, valuesToMatch)
   For i = 0 To CInt(collection.Count) - 1
      Set element = collection.Item(i)
      If element.Name = elementTagName Then
         matches = True
         For iVal = 0 To UBound(valuesToMatch) Step 2
            Set Property = element.GetPropertyByName(valuesToMatch(iVal))
            value = property.Value
            If Not value = Null Then
               value = CStr(value)
            End If
            If Not value = valuesToMatch(iVal + 1) Then
               matches = False
               Exit For
            End If
         Next
         If matches Then
            Exit For
         End If
      End If
   Next
   If matches Then
      FindElement = i
   Else
      FindElement = -1
   End If
End Function
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ