创建虚拟目录

来源:互联网 发布:少女终末旅行 知乎 编辑:程序博客网 时间:2024/04/28 17:57

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call CriaDiretorioVirtual("ssss", "1", "d:/", True)
        MessageBox.Show("创建成功")
    End Sub


    Function CriaDiretorioVirtual(ByVal vdirname As String, ByVal serverID As String, ByVal vdirPath As String, ByVal criaApplication As Boolean) As DirectoryEntry

        Dim newvdir As DirectoryEntry

        Dim root As DirectoryEntry

 

        root = New DirectoryEntry("IIS://local/W3SVC/" + serverID + "/Root")

 

        newvdir = root.Children.Add(vdirname, "IIsWebVirtualDir")

        newvdir.Properties("Path")(0) = vdirPath

 

        If criaApplication Then

            newvdir.Invoke("AppCreate", True)

            newvdir.Properties("AppFriendlyName")(0) = vdirname

            newvdir.Properties("AppIsolated")(0) = 2

        End If

        newvdir.CommitChanges()

 

        Return newvdir

    End Function