Turn: http://www.sostan.com/webscript/vbs-aspapppool/
ApplicationProgramThe pool needs to be recycled after being used for a period of time. If you want to use a program to control the pool, you can use vbs to implement the following:CodeAnd run the same on ASP.
SetApppools =GetObject("IIS: // localhost/w3svc/Apppools ")For EachApppoolInApppoolsMsgboxApppool. nameapppool. RecycleNext
The above program runs on the server where IIS is installed. All application pools are displayed. to recycle the specified application pool, you only need to determine the corresponding apppool. Name.
The following two methods are provided to operate the application pool:
1. Create a pool and Set Properties
Function Createapppool (newapppoolname) Set Apppools = GetObject ("IIS: // localhost/w3svc/ Apppools ") Set Newpool = Apppools. Create ("iisapplicationpool", newapppoolname) newpool. apppoolidentitytype = 2 'Pre-defined account 0 local system 1 Local Service 2 network service newpool. periodicrestartmemory = 512 * 1000 'Maximum virtual memory usage value newpool. periodicrestartprivatememory =500 * 1000 '100 physical memory limited' newpool. cpuaction = 0 'No operation is performed if the CPU usage exceeds 1. If the CPU usage exceeds 1, it is disabled. Newpool. cpulimit =" 80000 & Quot; 'maximum CPU newpool of 80%. periodicrestarttime = 180 Memory recovery time (minutes) newpool. cpuresetinterval = 2 'Refresh the CPU usage value (minutes) newpool. apppoolautostart = True 'Automatically start this pool newpool. setinfo Set Apppools = Nothing Set Newpool = Nothing If Err. Number = 0 Then Createapppool = True End Function
2. Set the properties of the application pool
Function Setapppoolsetting (apppoolname, values) setapppoolsetting = False Set Apps =GetObject ("IIS: // localhost/w3svc/apppools /"& Apppoolname) setvalue = Split (Values, "|") apps. cpulimit = Int (Setvalue ( 1 ))* 1000 'Maximum CPU percentage apps. cpuaction = Setvalue ( 2 ) 'Exceeds processing method 0 ignore 1 close apps. periodicrestartmemory = Int (Setvalue ( 3 ))*1024 'The virtual memory apps. periodicrestartprivatemory = Int (Setvalue ( 4 ))* 1024 'The physical memory apps. periodicrestarttime = Setvalue ( 5 ) 'Recycle time apps. setinfo Set Apps = Nothing Setapppoolsetting = True End Function
ASP. NET operations
http://topic.csdn.net/u/20090525/13/f1d14958-c2cc-4326-be1c-77112e1bb648.html
// Add application pool space reference 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) {// if the application pool does not exist, an error is reported. The system cannot find the specified path 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 ("application pool name started successfully", "started successfully");} catch (exception ex) {MessageBox. show (ex. message, "failed to start") ;}} private void button7_click (Object sender, system. eventargs e) {// if the current state of the application pool is stopped, an exception will occur and the string apppoolname = this will be reported. 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 ("application pool name recycling successful", "recycling successful");} catch (exception ex) {MessageBox. show (ex. message, "failed to recycle") ;}} 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 ("application pool name stopped successfully", "stopped successfully");} catch (exception ex) {MessageBox. show (ex. message, "failed to stop ");}}