仮想ディレクトリをチェックするより良い方法はありますか?そうでない場合は、それを作成しますか?

StackOverflow https://stackoverflow.com/questions/3472227

  •  28-09-2019
  •  | 
  •  

質問

開発者が環境を切り替えて別のプロジェクトに取り組むときに、仮想ディレクトリへのパスを設定するために使用する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

役に立ちましたか?

解決

あなたのアプローチは大丈夫です。これは、私が何年も前にIIS 5.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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top