I really hope everyone does fine.

I attempt to remove an online directory using WMi (Server Manager Class) and recreate with various values. The issue i'm facing would be that the virtual directory isn't getting erased. Help.

How you can check existance of the virtuual dir and also the call remove?

together with how check whether a directory is available before adding exactly the same again with slightly different qualities.

Essentially the aim ended up being to relabel a virtual directory together with renaming an internet site. I really hope i'm obvious

Here's my code.

Try
  Using mgr As New ServerManager()
    Dim site As Site = mgr.Sites(DomainName)
    Dim app As Application = site.Applications("/") '.CreateElement() '("/" & VirDirName)
    Dim VirDir As VirtualDirectory = app.VirtualDirectories.CreateElement()
         For Each VirDir In app.VirtualDirectories
              If VirDir("path") = "/" & VirDirName Then
                    app.VirtualDirectories.Remove(VirDir)
                    Exit For
              End If
         Next
         mgr.CommitChanges()
  End Using
 Catch Err As Exception
      Ex = Err
      Throw New Exception(Err.Message, Ex)
 End Try

Simply to clarify the code above isn't using WMI but Microsoft.Web.Administration (MWA).

Are you currently stating that your ultimate goal would be to relabel the site's directory or simply the website title? Should you alter the Sitename nothing further ought to be needed. When the goal would be to keep your directory title synchronized, then more often than not it's the cause of the website what you would like to relabel, so simply do something similar to:

Using mgr As New ServerManager() 
   Dim site As Site = mgr.Sites(DomainName) 
   site.Applications("/").VirtualDirectories("/").PhysicalPath = "...Whatever new physical Path"

   mgr.CommitChanges()
End Using