Jump to content

Recommended Posts

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
Posted

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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!

Posted

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
Posted (edited)

Figured it out. Needed to change:

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

To

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

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
×
×
  • Create New...