我正在使用计算机上的本地VBScript管理我的IIS应用程序池,或者通过在高权限身份下运行的ASP页面来管理我的IIS应用程序池。
Microsoft文档列出了此页面上{strong> ApplicationPool类对象的所有可用属性和方法https://msdn.microsoft.com/fr-fr/library/ms690608。
Altough我可以使用 .Recycle , .Start 和 .Stop 方法以及 .Name 属性,所有其他方法和属性不适用于应用程序池,例如 .GetState , .AutoStart , .ManagedPipelineMode ..
文档是否已损坏?
'For VBSCRIPT
Set o_Wbem_Locator = CreateObject("WbemScripting.SWbemLocator")
Set o_Wbem_Service = o_Wbem_Locator.ConnectServer("MyServerName", "root/MicrosoftIISv2")
Set o_Wbem_AppPoolsCollection = o_Wbem_Service.ExecQuery("SELECT * FROM IISApplicationPool")
For Each o_Wbem_AppPoolInstance In o_Wbem_AppPoolsCollection
'Work
o_Wbem_AppPoolInstance.Recycle
'Work
WScript.Echo o_Wbem_AppPoolInstance.Name
'DOES NOT Work
WScript.Echo o_Wbem_AppPoolInstance.GetState
'DOES NOT Work
WScript.Echo o_Wbem_AppPoolInstance.ManagedPipelineMode
Next
答案 0 :(得分:3)
这是解决方案:)
正如评论中 @ Kul-Tigin 所述,我正在连接错误的命名空间,并查询错误的对象类。
因此,使用Vbscript或ASP中的WMI管理IIS 7+应用程序池的正确工作代码如下:
'For VBSCRIPT
Set o_Wbem_Locator = CreateObject("WbemScripting.SWbemLocator")
'Suitable for IIS 6
'Set o_Wbem_Service = o_Wbem_Locator.ConnectServer("MyServerName", "root/MicrosoftIISv2")
'Suitable for IIS 7+
Set o_Wbem_Service = o_Wbem_Locator.ConnectServer("MyServerName", "root/WebAdministration")
'Suitable for IIS 6
'Set o_Wbem_AppPoolsCollection = o_Wbem_Service.ExecQuery("SELECT * FROM IISApplicationPool")
'Suitable for IIS 7+
Set o_Wbem_AppPoolsCollection = o_Wbem_Service.ExecQuery("SELECT * FROM ApplicationPool")
For Each o_Wbem_AppPoolInstance In o_Wbem_AppPoolsCollection
'Works in IIS 6 and in IIS 7+
o_Wbem_AppPoolInstance.Recycle
'Works in IIS 6 and in IIS 7+
WScript.Echo o_Wbem_AppPoolInstance.Name
'DOES NOT Work in IIS 6
'Works in IIS 7+
WScript.Echo o_Wbem_AppPoolInstance.GetState
'DOES NOT Work in IIS 6
'Works in IIS 7+
WScript.Echo o_Wbem_AppPoolInstance.ManagedPipelineMode
Next
我非常感谢 @ Kul-Tigin 指出所需语法中的这一根本区别,并且非常感谢所有其他评论员,这些评论员使我能够擦亮我的IIS应用程序池管理。我现在能够自动执行某些操作以确保我的应用程序池已启动,正常运行;)