0

開発者が別のプロジェクトで作業するために環境を切り替えるときに、仮想ディレクトリへのパスを設定するために使用するvbscriptコードがいくつかあります。現在、パスを設定しようとしていますが、エラーが発生した場合は作成します。変なにおいがします。仮想ディレクトリが存在するかどうかを確認する方法はありますか?そうでない場合は、それを作成しますか?

set objIIS = GetObject("IIS://" & strComputer & "/W3SVC/1/ROOT/SomeWeb")
objIIS.Path = strNewPath & "\SomeWeb"
objIIS.SetInfo

If Err.Number =  NOT_FOUND Then
    sVirtPath = strNewPath & "\SomeWeb"
CreateVirtualDirectory "SomeWeb", sVirtPath, true
Err.Clear
End If

これは問題なく機能しますが、何かが私に教えてくれます。もっと良い方法があるはずです。誰か提案はありますか?仮想ディレクトリの存在を確認するにはどうすればよいですか?フィードバックをいただければ幸いです。

ポインタをありがとう。
乾杯、
サンディエゴで〜ck

4

1 に答える 1

0

あなたのアプローチはうまくいくようです。これは、IIS5.0を使用して数年前に行ったわずかに異なるアプローチです。それ以降のバージョンのIISでも機能するかどうかはわかりませんが、役立つ場合があります。

Function IsExistingWebApp(strAppPath)
    Dim oWeb

    On Error Resume Next

    ' Assume it does not exist
    IsExistingWebApp = False

    Set oWeb = GetObject( strAppPath )
    If ( Err <> 0 ) Then
        ' If an error occurs then we know the application does not exist
        'LogMessage strAppPath & " does not exist as an application."

        Err = 0
        Exit Function
    Else
        If oWeb.Class = "IIsWebVirtualDir" Then
        'LogMessage "Found existing web application " & oWeb.AdsPath
        ' If it does exist and it is configured as a 
        ' virtual directory then rerturn true
        IsExistingWebApp = True
        End If      
    End If  
End Function
于 2010-08-12T21:54:55.053 に答える