天天看點

C# 操作IIS網站應用程式池

//添加應用程式池空間引用

using System.DirectoryServices;

C# 操作IIS網站應用程式池
C# 操作IIS網站應用程式池

代碼

   string method="Start"; //Start開啟  Recycle回收  Stop 停止

   string AppPoolName = "chengxuchiname";

   try

   {    

      DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");

      DirectoryEntry findPool = appPool.Children.Find(AppPoolName,"IIsApplicationPool");

      findPool.Invoke(method,null);

      appPool.CommitChanges();

      appPool.Close();

    MessageBox.Show("應用程式池名稱啟動成功","啟動成功"); 

   }

   catch(Exception ex)

   {

    MessageBox.Show(ex.Message,"啟動失敗");