【发布时间】:2009-03-20 17:51:15
【问题描述】:
作为卸载方法的一部分,我需要从 .NET 中删除虚拟目录和应用程序池。我在网上某处找到了以下代码:
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.");
}
}
但它似乎在tree.CommitChanges(); 上抛出了COMException。我需要这条线吗?这是一个正确的方法吗?
【问题讨论】:
-
你能粘贴完整的 COMException 吗?
-
您确实应该使用 Windows 安装程序来执行这些操作。 Wix 内置了自动创建和删除 IIS 对象的功能。
-
@Jesse - 使用 Wix 是否可以提示用户输入新的应用程序池/网站/vdir 而不是选择现有的(VS Web 设置项目只允许您选择现有的 IIS 对象)?
标签: c# .net iis installation wmi