直接代码:
代码
using
System.DirectoryServices;
//
添加引用 System.DirectoryServices
try
{
DirectoryEntry appPool = new DirectoryEntry( " IIS://localhost/W3SVC/AppPools " );
DirectoryEntry findPool = appPool.Children.Find( " DefaultAppPool " , " IIsApplicationPool " );
findPool.Invoke( " Start " , null ); // Start|Stop|Recycle [Recycle:应用程序池回收,如果状态为Stop会报错]
appPool.CommitChanges();
appPool.Close();
Response.Write( " DefaultAppPool 操作成功! " );
}
catch (Exception ex)
{
Response.Write( " DefaultAppPool 未找到! " );
}
try
{
DirectoryEntry appPool = new DirectoryEntry( " IIS://localhost/W3SVC/AppPools " );
DirectoryEntry findPool = appPool.Children.Find( " DefaultAppPool " , " IIsApplicationPool " );
findPool.Invoke( " Start " , null ); // Start|Stop|Recycle [Recycle:应用程序池回收,如果状态为Stop会报错]
appPool.CommitChanges();
appPool.Close();
Response.Write( " DefaultAppPool 操作成功! " );
}
catch (Exception ex)
{
Response.Write( " DefaultAppPool 未找到! " );
}
如果本文对你有所帮助,请打赏——1元就足够感动我:)
联系邮箱:intdb@qq.com
我的GitHub: https://github.com/vipstone
联系邮箱:intdb@qq.com
我的GitHub: https://github.com/vipstone
关注公众号:
作者: 王磊
出处: http://vipstone.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,请标明出处。