Pergunta

Eu tenho algum código VBScript que eu uso para definir caminhos para diretórios virtuais quando um desenvolvedor muda seu ambiente para trabalhar em outro projeto. Atualmente, tentamos definir o caminho e, se houver um erro, criamos. Só cheira engraçado. Existe uma maneira de verificar se existe um diretório virtual? E se não, crie isso?

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

Isso funciona muito bem, mas algo me diz, deve haver uma maneira melhor. Alguém tem alguma sugestão? Como faço para ver a existência de um diretório virtual? Qualquer feedback é apreciado.

Obrigado por quaisquer indicadores.
Saúde,
~ ck em San Diego

Foi útil?

Solução

Sua abordagem parece boa. Aqui está uma abordagem um pouco diferente que fiz anos atrás ao trabalhar com o IIS 5.0. Não tenho certeza se ainda funcionaria em versões posteriores do IIS, mas você pode achar útil.

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top