C#操作IIS回收应用程序池,兼容iis6和iis7

try
{
string method = "Recycle";
string AppPoolName = this.textBox2.Text.Trim();
DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
DirectoryEntry findPool = appPool.Children.Find(AppPoolName, "IIsApplicationPool");
findPool.Invoke(method, null);
appPool.CommitChanges();
appPool.Close();
this.textBox1.Text = string.Format("回收应用程序池{0}成功", AppPoolName, method);
}
catch (Exception ex)
{
throw ex;
}

原文地址:https://www.cnblogs.com/leku_cc/p/2879889.html