Sign in to follow this  
Followers 0
buymeapc

How can I get IIS7 application pool details?

7 posts in this topic

#1 ·  Posted (edited)

Hi all,

I'm looking to get a list of the application pools and the virtual directories (applications) that are within each pool listed out into an array from IIS7. I'm having no luck with the WMI code I've found online. I don't really want to use "appcmd.exe" either since I also need to find some properties of the applciation pools as well, such as:

  • Periodic Restart Requests
  • Periodic Restart Time
  • Idle Timeout
  • App Pool Queue Length
  • Etc...
Here's the code I have thus far and it seems to be bailing on the InstancesOf command and not returning any results. What could I be missing? Thanks for the help.

;AppPool Enum
Dim $oWebAdmin, $oApps, $oApp
$oWebAdmin = ObjGet("winmgmts:rootWebAdministration")
If IsObj($oWebAdmin) = 0 Then
MsgBox(0, "", "Not an object")
Exit
EndIf
$oApps = $oWebAdmin.InstancesOf("Application")
For $oApp In $oApps
MsgBox(0, $oApp.SiteName, "Web site/Application: " & $oApp.SiteName & $oApp.Path &@CRLF&"Application Pool: " & $oApp.ApplicationPool &@CRLF&"Enabled protocol(s): " & $oApp.EnabledProtocols)
Next
Edited by buymeapc

Share this post


Link to post
Share on other sites



I would suggest to implement an COM error handler. Please have a look at ObjEvent in the help file.

Split the MsgBox statement so that each property is displayed separately.

If you get an error message you see exactly which property causes the problem.

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler

; Your code goes here

Exit

; This is my custom defined error handler
Func MyErrFunc()

  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"   & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"  & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "      & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "  & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "      & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "      & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )

Endfunc

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for the help! Here's the response I'm receiving after I added the error handler you suggested (image attached). After doing a quick Google search, I found this website http://www.computerperformance.co.uk/Logon/code/code_80041013.htm and I followed what it said even though it sounded a bit weird. Still no luck, though.

post-8728-0-78127800-1322515402_thumb.jp

Edited by buymeapc

Share this post


Link to post
Share on other sites

The error code 0x80041013 you get means: "WBEM_E_PROVIDER_LOAD_FAILURE". According to Microsoft this could be on of the following problems:

COM cannot locate a provider referenced in the schema.

This error may be caused by many conditions, including the following:

  • Provider is using a WMI DLL that does not match the .lib file used when the provider was built.
  • Provider's DLL, or any of the DLLs on which it depends, is corrupt.
  • Provider failed to export DllRegisterServer.
  • In-process provider was not registered using the regsvr32 command.
  • Out-of-process provider was not registered using the /regserver switch. For example, myprog.exe /regserver.
WMI might not be running on the web server?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

After checking all the advanced things, I had one of those "DUH :D" moments. I realized UAC is enabed...it disables WMI calls unless the applciation is run with elevated permissions. As soon as I ran this "as administrator", even though I'm already an admin, everything worked perfectly. Thanks for your help!

Share this post


Link to post
Share on other sites

Ok, now I'm trying to get the periodic restart schedule for the application pools in IIS7. The code I have doesn't quite work though. Could anyone tell me what I might be missing? Thanks!

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler
Dim $oWebAdmin, $oApps, $oApp
$oWebAdmin = ObjGet("winmgmts:root\WebAdministration")
If IsObj($oWebAdmin) = 0 Then
MsgBox(0, "", "Not an object")
Exit
EndIf
$oApps = $oWebAdmin.InstancesOf("Application")
For $oApp In $oApps
$schedText = ""
For $sched In $oApp.Recycling.PeriodicRestart.Schedule
  For $vProp In $sched.Properties
   $schedText &= $vProp.Value
  Next
Next
MsgBox(0, "", $schedText)
;MsgBox(0, $oApp.ApplicationPool, $oApp.ApplicationPool.Recycling.PeriodicRestart.Schedule)
;MsgBox(0, $oApp.SiteName, "Web site/Application: " & $oApp.SiteName & $oApp.Path &@CRLF&"Application Pool: " & $oApp.ApplicationPool &@CRLF&"Enabled protocol(s): " & $oApp.EnabledProtocols);&@CRLF&"Idle TimeOut: "&$oApp.ProcessModel.IdleTimeout)
Next
Exit
; This is my custom defined error handler
Func MyErrFunc()
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"   & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"  & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "    & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "  & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "    & @TAB & $oMyError.source    & @CRLF & _
             "err.helpfile is: "      & @TAB & $oMyError.helpfile    & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
Endfunc

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Figured it out. Needed to change:

$oApps = $oWebAdmin.InstancesOf("Application")

To

$oApps = $oWebAdmin.InstancesOf("ApplicationPool")
Edited by buymeapc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0