开始使用MyAppPool iisapp.vbs [英] Start MyAppPool using iisapp.vbs
问题描述
我有一个使用下面的脚本来回收 MyAppPool
。
I have a batch file that uses the following script to recycle MyAppPool
.
cscript.exe %windir%\system32\iisapp.vbs /a MyAppPool /r
然而,当被停止 MyAppPool
,那么我无法回收。我要的是检查天气 MyAppPool
停止,如果停止,启动它,回收它,然后再停止。
However when MyAppPool
is Stopped, then I am not able to recycle it. What I want is to check weather MyAppPool
is Stopped, if stopped , then Start it, recycle it and then Stop again.
好吧,我在这一个完整的新手IIS的事情,从来没有在它的工作。我使用的是Window Server 2003和IIS6。
Well I am a complete newbie in this IIS thing and have never worked in it. I am using Window Server 2003 and IIS6.
推荐答案
您可以编写自己的.vbs脚本,来查找程序池的.STATE,当它停止启动。是这样的:
You can write your own .vbs script, to lookup the .State of the AppPool, and start it when it's stopped. Something like:
//编辑:
Option Explicit
If WScript.Arguments.Count <> 1 Then
Wscript.Echo "No AppPoolName provided. Iterate through all AppPools"
iterate_and_start_all_apps()
Else
Dim AppPoolName
AppPoolName = Wscript.Arguments(0)
'
' Choose what to do here and uncomment that Sub
'
' start_given_app(AppPoolName)
' start_one_app_if_stopped(AppPoolName)
' start_recycle_stop_app(AppPoolName)
End If
' This Sub is runs if no argument is passed to the script
Sub iterate_and_start_all_apps()
Dim objAppPools, objAppPool
Set objAppPools = GetObject("IIS://Localhost/W3SVC/AppPools")
For Each objAppPool in objAppPools
Set objAppPool = GetObject("IIS://Localhost/W3SVC/AppPools/" & objAppPool.Name )
If objAppPool.AppPoolState <> 2 Then
Wscript.Echo objAppPool.Name & " is not running."
WScript.Echo objAppPool.Name & ", AppPoolState: " & objAppPool.AppPoolState & _
", Win32Error: " & objAppPool.Win32Error & " ("& hex(objAppPool.Win32Error)&")"
Wscript.Echo State2Desc(objAppPool.AppPoolState)
objAppPool.Start
If Err.Number = 0 Then
Wscript.Echo objAppPool.Name & " started."
End If
End If
Next
Set objAppPool = Nothing
Set objAppPools = Nothing
End Sub
'
' start an application pool if the .State is stopped
'
Sub start_one_app_if_stopped(applicationpool)
Dim iisObjectPath : iisObjectPath = ("IIS://Localhost/W3SVC/AppPools/" & applicationpool)
Dim iisObject : Set iisObject = GetObject(iisObjectPath)
If iisObject.AppPoolState <> 2 Then
iisObject.Start
If (Err.Number <> 0) Then
WScript.Echo "Error starting: " & ObjectPath
WScript.Quit (Err.Number)
Else
WScript.Echo applicationpool & " started."
End If
End If
Set iisObject = nothing
Set iisObjectPath = nothing
End Sub
'
' if an application pool is stopped, start + recycle + stop it
'
Sub start_recycle_stop_app(applicationpool)
Dim iisObjectPath : iisObjectPath = ("IIS://Localhost/W3SVC/AppPools/" & applicationpool)
Dim iisObject : Set iisObject = GetObject(iisObjectPath)
If iisObject.AppPoolState <> 2 Then
iisObject.Start
If (Err.Number <> 0) Then
WScript.Echo "Error starting: " & ObjectPath
WScript.Quit (Err.Number)
Else
WScript.Echo applicationpool & " started."
End If
iisObject.recycle
' we need to sleep for some time because recyle takes some time
wscript.sleep(3000)
iisObject.Stop
End If
Set iisObject = nothing
Set iisObjectPath = nothing
End Sub
'
' just issue a start command to start an application pool
'
Sub start_given_app(applicationpool)
Dim iisObjectPath : iisObjectPath = ("IIS://Localhost/W3SVC/AppPools/" & applicationpool)
Dim iisObject : Set iisObject = GetObject(iisObjectPath)
IIsObject.Start
If (Err.Number <> 0) Then
WScript.Echo "Error starting: " & ObjectPath
WScript.Quit (Err.Number)
Else
WScript.Echo applicationpool & " started."
End If
Set iisObject = nothing
Set iisObjectPath = nothing
End Sub
'
' support function
'
Function State2Desc(nState)
Select Case nState
Case 1
State2Desc = "Starting"
Case 2
State2Desc = "Started"
Case 3
State2Desc = "Stopping"
Case 4
State2Desc = "Stopped"
Case Else
State2Desc = "Unknown state"
End Select
End Function
(从 http://www.saotn.org参加/ IIS-60-启动gestopte - 应用 - 池/ ,这是一个脚本启动所有应用程序池)。
(part taken from http://www.saotn.org/iis-60-start-gestopte-application-pools/, which is a script to start all application pools).
另存为startapp.vbs'和运行:
Save as 'startapp.vbs' and run with:
cscript.exe /nologo startapp.vbs name_of_appPool
如果你不带参数启动它,那么脚本将通过在元数据库中的所有应用程序池迭代,并开始他们,如果他们没有运行。
if you start it without an argument, then the script will iterate through all applications pools in the the metabase and start them if they're not running.
我想你会需要start_one_app_if_stopped子,所以uncoment该线(13号线),并用命令行参数运行.vbs脚本:
I think you'll need the "start_one_app_if_stopped" Sub, so uncoment that line (line 13) and run the .vbs script with an command line argument:
cscript.exe /nologo startapp.vbs name_of_appPool
心连心
这篇关于开始使用MyAppPool iisapp.vbs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!