Click here to Skip to main content
13,088,846 members (54,874 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi All,

I'm trying to install a web setup in that i'm using custom actions for deleting the default virtual directories which is created by the MSI and creating custom virtual directories.
The directories are creating fine, but the when I reset the IIS the custom virtual directories are gone and the deleted default virtual directories are came.

Resources used : Windows server 2003, IIS 6

Here the code used for deleting virtual directory and creatign virtual directory

Create Virtual Directory:
<pre lang="vb">Private Sub CreateVDir(ByVal strMetabasePath As String, ByVal strVdirName As String, ByVal strPhysicalPath As String, ByVal AppName As String)
            Dim objSite As New DirectoryEntry(strMetabasePath)
            If (CheckIfVDirExists(objSite, strVdirName)) Then
            End If
            Dim strClassName As String = objSite.SchemaClassName.ToString()
            If strClassName.EndsWith("Server") OrElse strClassName.EndsWith("VirtualDir") Then
                Dim objVdirs As DirectoryEntries = objSite.Children
                Dim objNewVdir As DirectoryEntry = objVdirs.Add(strVdirName, strClassName.Replace("Service", "VirtualDir"))
                objNewVdir.Properties("Path")(0) = strPhysicalPath
                objNewVdir.Properties("AccessScript")(0) = True
                objNewVdir.Properties("AppFriendlyName")(0) = strVdirName
                objNewVdir.Properties("AppIsolated")(0) = "1"
                objNewVdir.Properties("AppPoolId").Value = AppName
                objNewVdir.Properties("AppRoot")(0) = "/LM" + strMetabasePath.Substring(strMetabasePath.IndexOf("/", "IIS://".Length))
                objNewVdir.Properties("AppFriendlyName")(0) = strVdirName
                objNewVdir.Invoke("AppCreate", True)
                Throw New InstallException("Failed. A virtual directory can only be created in a site or virtual directory node.")
            End If
        Catch exError As Exception
            Throw exError
        End Try
    End Sub
Delete Virtual Directory:
Private Sub DeleteVirtualDirectory(ByVal VirtualDirName As String)
            Dim Parent As New DirectoryEntry(StrMetabasePath)
            Dim Parameters As [Object]() = {"IIsWebVirtualDir", VirtualDirName}
            Parent.Invoke("Delete", Parameters)
        Catch ex As Exception
           Throw New InstallException("Error While deleting the virtual directories." & ex.Message)
        End Try
    End Sub

Posted 25-Mar-13 5:00am
Updated 25-Mar-13 5:09am
iismoove 2-Apr-13 15:10pm
Have you tried stopping IIS before you delete the VDir? I noticed with our IIS, we need to stop it, create/delete the VDir, and then restart IIS.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100