参考文章:
http://blogs.msdn.com/carlosag/archive/2006/04/17/MicrosoftWebAdministration.aspx
http://dflying.cnblogs.com/archive/2006/04/17/377276.html
1. 添加引用
2. 编写代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Web.Administration;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//取得所有的网站及其应用程序的信息
ServerManager iis = new ServerManager();
foreach (var item in iis.Sites)
{
Console.WriteLine("网站:{0}", item.Name);
foreach (var app in item.Applications)
{
Console.WriteLine("\t应用:{0}", app.Path);
}
}
}
}
}
3. 运行效果