Click here to Skip to main content
11,806,590 members (41,313 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: IIS6 VB IIS VB.NET
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
Edited 25-Mar-13 5:09am
iismoove at 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
0 ppolymorphe 295
1 OriginalGriff 150
2 George Jonsson 135
3 Richard Deeming 120
4 CPallini 100
0 OriginalGriff 3,380
1 Maciej Los 1,990
2 CPallini 1,915
3 KrunalRohit 1,907
4 ppolymorphe 1,317

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2015
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