Wanna know which application pool is used by your application?

Some times I check if my applications are still using the proper application pools (I am not the only administrator of the IIS servers 😉 ). You can do this with the IIS GUI ofcourse but you can also use scripting (checking a lot of servers/application and application pools can be a pain in the !@#$%). So I created a little script to do that.
Some times I check if my applications are still using the proper application pools (I am not the only administrator of the IIS servers 😉 ).
You can do this with the IIS GUI ofcourse but you can also use scripting (checking a lot of servers/application and application pools can be a pain in the !@#$%).
So I created a little script to do that.

'--------------------------------------------------------------------------

Option Explicit

'--------------------------------------------------------------------------
' init
'--------------------------------------------------------------------------

Dim oIIS
Dim sDataPath
Dim cDataPaths
Dim sAppPoolID
Dim oWMI
Dim cProcessList
Dim oProcess

'--------------------------------------------------------------------------
' Main routine
'--------------------------------------------------------------------------

Set oIIS = GetObject("IIS://localhost/w3svc")
cDataPaths = oIIS.GetDataPaths("AppPoolId",0)
For Each sDataPath In cDataPaths
WScript.Echo "------------------------------------------------------------"
sAppPoolID = GetObject(sDataPath).AppPoolId
WSCript.Echo "Metabase Path: " & sDataPath
WScript.Echo "Appication Pool: " & sAppPoolID
WScript.Echo "W3wp.exe Pid: " & GETWPPID(sAppPoolID)
Next
WScript.Echo "------------------------------------------------------------"

'--------------------------------------------------------------------------

'--------------------------------------------------------------------------
' Functions and Subs
'--------------------------------------------------------------------------

Function GETAPID(sArg)
Dim Submatches
Dim sAppPoolid
Dim re
Dim Matches

On Error Resume Next

Set re = New RegExp
re.Pattern = "-ap ""(.+)"""
re.IgnoreCase = True
Set Matches = re.Execute(sArg)
Set SubMatches = Matches(0).Submatches
sAppPoolid = Submatches(0)

GETAPID = sAppPoolid
End Function

Function GETWPPID(sAppPool)
Set oWMI = GetObject("winmgmts:\root\cimv2")
Set cProcessList = oWMI.ExecQuery("Select * from Win32_Process WHERE Name='w3wp.exe'")
For Each oProcess In cProcessList
If GETAPID(oProcess.CommandLine) = sAppPool Then
GETWPPID = oProcess.ProcessID
Exit Function
End If
Next
GETWPPID = "Application Pool is not running"
End Function

'--------------------------------------------------------------------------

Warning: count(): Parameter must be an array or an object that implements Countable in /home/gafec/public_html/adaptive-techniques-net/wp-includes/class-wp-comment-query.php on line 405

Leave a Reply

Your email address will not be published. Required fields are marked *