Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 163351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:33:08+00:00 2026-05-11T11:33:08+00:00

I need to delete a Virtual Directory and Application pool from .NET as part

  • 0

I need to delete a Virtual Directory and Application pool from .NET as part of my uninstall method. I found the following code on the web somewhere:

    private static void DeleteTree(string metabasePath)     {         // metabasePath is of the form 'IIS://<servername>/<path>'         // for example 'IIS://localhost/W3SVC/1/Root/MyVDir'          // or 'IIS://localhost/W3SVC/AppPools/MyAppPool'         Console.WriteLine('Deleting {0}:', metabasePath);          try         {             DirectoryEntry tree = new DirectoryEntry(metabasePath);             tree.DeleteTree();             tree.CommitChanges();             Console.WriteLine('Done.');         }         catch (DirectoryNotFoundException)         {             Console.WriteLine('Not found.');         }     } 

but it seems to throw a COMException on tree.CommitChanges();. Do I need this line? Is it a correct approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:33:09+00:00Added an answer on May 11, 2026 at 11:33 am

    If you’re deleting objects such as application pools, virtual directories or IIS applications, you need to do it like this:

    string appPoolPath = 'IIS://Localhost/W3SVC/AppPools/MyAppPool'; using(DirectoryEntry appPool = new DirectoryEntry(appPoolPath)) {     using(DirectoryEntry appPools =                 new DirectoryEntry(@'IIS://Localhost/W3SVC/AppPools'))     {         appPools.Children.Remove(appPool);         appPools.CommitChanges();     } } 

    You create a DirectoryEntry object for the item you want to delete then create a DirectoryEntry for its parent. You then tell the parent to remove that object.

    You can also do this as well:

    string appPoolPath = 'IIS://Localhost/W3SVC/AppPools/MyAppPool'; using(DirectoryEntry appPool = new DirectoryEntry(appPoolPath)) {     using(DirectoryEntry parent = appPool.Parent)     {         parent.Children.Remove(appPool);         parent.CommitChanges();     } } 

    Depending on the task in hand I’ll use either method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I have successfully used the TPaintBox component with the DevExpress… May 11, 2026 at 12:56 pm
  • added an answer If you could wait, Symfony support is coming to Netbeans… May 11, 2026 at 12:56 pm
  • added an answer You need to assign it. If you go into script/console:… May 11, 2026 at 12:56 pm

Related Questions

I need to delete a temporary file from my C++ windows application (developed in
I need to delete a regsitry key. It has a deny ACL on Set
I need to delete files of a certain type (.zip files, say) from a
I need a way to recursively delete a folder and its children. Is there
I need to send PUT and DELETE along with POST, GET to a REST
Win32's CreateFile has FILE_FLAG_DELETE_ON_CLOSE , but I'm on Linux. I want to open a
I'm writing a shell script to do some web server configuration. I need to
I'm trying to use NAnt/NAntContrib build script to build a web application on Windows
So I have this library code, see... class Thing { public: class Obj {

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.