首页 » ASP代码 » adsi操作iis应用程序池

adsi操作iis应用程序池

An application pool provides you with a way of isolating Web sites and Directories from each other even though they are being hosted on a common server. Each application pool is given its own set of server resources and can be configured with different identities. That way, if a Web site crashes, it won’t effect sites in other application pools.

A example of this is a Web site which has a memory leak. If all of the Web sites hosted on a particular server were to share the system resources as was the case with IIS 5.1 and earlier and one of the Web sites had a memory leak, it could potentially take memory away from the other hosted sites.

If the leaky site were in its own application pool though, the memory leak would not effect any other site because each application pool has its own server resources including memory.

On earlier versions of IIS you could only configure your sites to run either Low ( In Process ) with the IIS Engine, Medium ( Pooled ) where all applications shared a pool of memory, and High (Out Of Process). The problem with this is that a bad application could depending on the isolation level take down the IIS server, or all other sites in the Medium ( Pooled ) model.

Each application pool can be recycled based on a memory limit, the time of day, a number of requests or just after a period of time. Each application pool can also run with its own identity which can be either Local System, Local Service, Network Service or a custom credential.

Application pools are available only when IIS is running in worker process isolation mode (this is the default). If you are running IIS in IIS 5 isolation mode, then the application pools will not be accessible to you.

There is only one application pool by default called DefaultAppPool. When you create new Web sites, the newly created sites by default will use the DefaultAppPool unless you reconfigure the site after it is created. IIS does not automatically create a separate application pool for each Web site.

Note: If you are running ASP.NET 1.1 and 2.0 then they must run in two different application pools as you can only load one version of the .NET framework into an application pool.

Below are a number of very simple scripts that you could use to view / add and edit application pools.

Note: Application Pools are only supported on IIS 6 and later.

Enumerating Application Pools

This simple script will simply display the name of each application pool on the local server.

option explicit

dim objAppPools, objAppPool

Set objAppPools = GetObject("IIS://localhost/W3SVC/AppPools")
for each objAppPool in objAppPools
	WScript.echo objAppPool.Name
next

 Enumerating Applications in an Application Pool

This script will display the web sites / directories that are using the DefaultAppPool

option explicit

dim Applications, objAppPool, index

Set objAppPool = GetObject("IIS://localhost/W3SVC/AppPools/DefaultAppPool")
WScript.echo objAppPool.Name 

Applications = objAppPool.EnumAppsInPool()
for index = 0 to UBound(Applications)
	WScript.echo "   " & Applications(index)
next

 Enumerating Application Pool Properties

This script will display all properties of an application pool by looking at the Schema object for an Application Pool.

option explicit

dim Applications, objAppPools, objAppPool, index, IIsSchemaObject
dim PropertyName, IIsAppPoolObject, ValueList

set IIsSchemaObject = GetObject("IIS://localhost/schema/IIsApplicationPool")
set IIsAppPoolObject = GetObject("IIS://localhost/W3SVC/AppPools/DefaultAppPool")

on error resume next

For Each PropertyName In IIsSchemaObject.MandatoryProperties
	WScript.echo PropertyName
next

For Each PropertyName In IIsSchemaObject.OptionalProperties
	WScript.echo PropertyName
	ValueList = IIsAppPoolObject.Get(PropertyName)
	if (isArray(ValueList) = true) then
		for index = lbound(ValueList) to ubound(ValueList)
			WScript.echo " " & index & " - " & ValueList(index)
		next
	else
		WScript.echo " " & ValueList
	end if
next

 Enumerating the Periodic Recycling of all Application Pools

This script will display the recycling settings of all application pools. You may find that your application stops briefly and that could be caused by the application pool being recycled every 1740 minutes ( every 29 hours) which is the default.

option explicit

dim objAppPools, objAppPool, Schedule

Set objAppPools = GetObject("IIS://localhost/W3SVC/AppPools")
for each objAppPool in objAppPools
	WScript.echo objAppPool.Name
	WScript.echo "  Restart Time           : " & objAppPool.PeriodicRestartTime & " seconds"
	WScript.echo "  Restart Requests       : " & objAppPool.PeriodicRestartRequests
	WScript.echo "  Restart Memory         : " & objAppPool.PeriodicRestartMemory
	WScript.echo "  Restart Private Memory : " & objAppPool.PeriodicRestartPrivateMemory
	WScript.echo "  Restart Requests       : " & objAppPool.PeriodicRestartRequests
	for each Schedule in objAppPool.PeriodicRestartSchedule
		WScript.echo "  Restart At             : " & Schedule
	next
	WScript.echo
next

 Creating an Application Pool

This script will create a new application pool using the defaults.

strAppPool = "MyAppPool1"
Set objAppPools = GetObject("IIS://localhost/W3SVC/AppPools")
Set objAppPool = objAppPools.Create("IIsApplicationPool", strAppPool)
objAppPool.SetInfo

 Creating an Application Pool to run with a specific identity

This script will create a new application pool to run as a custom identity. This custom identity could be a local or domain account. You will need to add the user account into the IIS_WPG group on the IIS server. This is because this group has been assigned permissions that the application pool will need to run properly.

strAppPool = "MyAppPool2"
Set objAppPools = GetObject("IIS://localhost/W3SVC/AppPools")
Set objAppPool = objAppPools.Create("IIsApplicationPool", strAppPool)

' 0 = Local System
' 1 = Local Service
' 2 = Network Service
' 3 = Custom Identity -> also set WAMUserName and WAMUserPass
objAppPool.AppPoolIdentityType = 3

' Note: WamUserName must be added to the IIS_WPG group to have correct security rights
objAppPool.WAMUserName = "DOMAIN\Username"
objAppPool.WAMUserPass = "Password"

objAppPool.SetInfo

 Starting an Application Pool

This script will allow you to start an application pool. You can also specify Stop() and Recycle()  instead of Start().

option explicit

dim objAppPool

Set objAppPool = GetObject("IIS://localhost/W3SVC/AppPools/DefaultAppPool")
objAppPool.Start()

 

Hopefully these simple scripts will show you how easy Application Pools are to create and enumerate.

, ,

转发到新浪微博 转发到新浪微博

目前这篇文章有5条评论(Rss)

  1. bookmarking | #2
    05/16/2012 at 10:18

    EObmnS Say, you got a nice post.Much thanks again. Fantastic.

  2. seo katalog | #3
    05/16/2012 at 12:53

    Thanks for your posting. I also feel that laptop computers have grown to be more and more popular currently, and now in many cases are the only kind of computer found in a household. The reason being at the same time potentially they are becoming more and more inexpensive, their processing power is growing to the point where there’re as potent as desktop computers through just a few years ago.

  3. oakley antix sunglasses wholesale | #4
    05/16/2012 at 19:44

    It is actually a great and useful piece of info. I¡¦m happy that you simply shared this useful info with us. Please keep us up to date like this. Thanks for sharing.

  4. motorola droid accessories | #5
    05/17/2012 at 00:36

    Thanks a lot for sharing this with all of us you really know what you are talking about! Bookmarked. Please also visit my web site =). We could have a link exchange arrangement between us!

我要评论