adsi操作iis应用程序池
作者:佚名 时间:2012-04-13
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 explicitdim objAppPools, objAppPoolSet objAppPools = GetObject("IIS://localhost/W3SVC/AppPools")for each objAppPool in objAppPoolsWScript.echo objAppPool.Namenext |
Enumerating Applications in an Application Pool
This script will display the web sites / directories that are using the DefaultAppPool
option explicitdim Applications, objAppPool, indexSet 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 explicitdim Applications, objAppPools, objAppPool, index, IIsSchemaObjectdim PropertyName, IIsAppPoolObject, ValueListset IIsSchemaObject = GetObject("IIS://localhost/schema/IIsApplicationPool")set IIsAppPoolObject = GetObject("IIS://localhost/W3SVC/AppPools/DefaultAppPool")on error resume nextFor Each PropertyName In IIsSchemaObject.MandatoryPropertiesWScript.echo PropertyNamenextFor Each PropertyName In IIsSchemaObject.OptionalPropertiesWScript.echo PropertyNameValueList = IIsAppPoolObject.Get(PropertyName)if (isArray(ValueList) = true) thenfor index = lbound(ValueList) to ubound(ValueList)WScript.echo " " & index & " - " & ValueList(index)nextelseWScript.echo " " & ValueListend ifnext |
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 explicitdim objAppPools, objAppPool, ScheduleSet objAppPools = GetObject("IIS://localhost/W3SVC/AppPools")for each objAppPool in objAppPoolsWScript.echo objAppPool.NameWScript.echo " Restart Time : " & objAppPool.PeriodicRestartTime & " seconds"WScript.echo " Restart Requests : " & objAppPool.PeriodicRestartRequestsWScript.echo " Restart Memory : " & objAppPool.PeriodicRestartMemoryWScript.echo " Restart Private Memory : " & objAppPool.PeriodicRestartPrivateMemoryWScript.echo " Restart Requests : " & objAppPool.PeriodicRestartRequestsfor each Schedule in objAppPool.PeriodicRestartScheduleWScript.echo " Restart At : " & SchedulenextWScript.echonext |
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 WAMUserPassobjAppPool.AppPoolIdentityType = 3' Note: WamUserName must be added to the IIS_WPG group to have correct security rightsobjAppPool.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 explicitdim objAppPoolSet objAppPool = GetObject("IIS://localhost/W3SVC/AppPools/DefaultAppPool")objAppPool.Start()