利用VBS或ASP指令碼回收操作應用程式集區

來源:互聯網
上載者:User

轉 : http://www.sostan.com/webscript/vbs-aspapppool/

應用程式集區在使用一段時間後需要回收,想用程式來控制,就用vbs實現了以下代碼,在asp上一樣運行。

set apppools = GetObject(“IIS://LocalHost/W3SVC/AppPools”)for each apppool in apppoolsmsgbox apppool.nameapppool.recyclenext

 

上面的程式在安裝有iis的伺服器上面運行,即可彈出所有的應用程式集區,想回收指定的應用程式集區,只需要判斷相應的apppool.name即可。

下面提供兩個操作應用程式集區的方法:
1. 建立一個池並設定屬性

function CreateAppPool(NewAppPoolName)Set AppPools = GetObject(“IIS://localhost/W3SVC/AppPools”)set NewPool = AppPools.Create(“IIsApplicationPool”, NewAppPoolName)NewPool.AppPoolIdentityType = 2′預定義賬戶0本地系統1本地服務2網路服務NewPool.PeriodicRestartMemory = 512 * 1000 ‘最大虛擬記憶體使用值NewPool.PeriodicRestartPrivateMemory = 500 * 1000 ’500實體記憶體限制’NewPool.CPUAction = 0′超過CPU不操作,1就是超過cpu就關閉。NewPool.CPULimit = “80000″‘最大80%的CPUNewPool.PeriodicRestartTime = 180′記憶體回收時間(分鐘)NewPool.CPUResetInterval = 2′重新整理CPU使用率值(分鐘)NewPool.AppPoolAutoStart = true’自動啟動此池NewPool.SetInfoSet AppPools = nothingset NewPool = nothingif err.number=0 then CreateAppPool=trueend function

2. 設定應用程式集區的屬性

function SetAppPoolSetting(AppPoolName,Values)SetAppPoolSetting=falseSet apps=GetObject(“IIS://localhost/w3svc/AppPools/”&AppPoolName)SetValue=split(Values,”|”)apps.CpuLimit=int(SetValue(1))*1000′最大CPU百分比apps.CPUAction=SetValue(2)’超過處理方式0忽略1關閉apps.PeriodicRestartMemory=int(SetValue(3))*1024′虛擬記憶體apps.PeriodicRestartPrivateMemory=int(SetValue(4))*1024′實體記憶體apps.PeriodicRestartTime=SetValue(5)’回收時間apps.SetInfoset apps=nothingSetAppPoolSetting=trueend function

ASP.NET操作

http://topic.csdn.net/u/20090525/13/f1d14958-c2cc-4326-be1c-77112e1bb648.html

//添加應用程式集區空間引用using System.DirectoryServices;using System.Text; using System.Text.RegularExpressions; using System.Diagnostics; using System.Management;private void button6_Click(object sender, System.EventArgs e)  {   //如果應用程式集區不存在,則會報錯系統找不到指定路徑   string AppPoolName=this.textBox1.Text.Trim();   string method="Start";   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,"啟動失敗");         }  }  private void button7_Click(object sender, System.EventArgs e)  {   //如果應用程式集區目前狀態為停止,則會發生異常報錯   string AppPoolName=this.textBox1.Text.Trim();   string method="Recycle";   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,"回收失敗");         }    }  private void button8_Click(object sender, System.EventArgs e)  {   string AppPoolName=this.textBox1.Text.Trim();   string method="Stop";   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,"停止失敗");         }    } 

  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.