设为首页 收藏本站
查看: 738|回复: 0

[经验分享] IIS 6.0, Getting Information Using WMI

[复制链接]

尚未签到

发表于 2015-8-14 09:03:02 | 显示全部楼层 |阅读模式
  reference :http://msdn2.microsoft.com/en-us/library/ms524913.aspx
reference : http://www.aspfree.com/c/a/IIS/IIS-60-Getting-Information-Using-WMI/
IIS 6.0, Getting Information Using WMI
(Page 1 of 5 )
  In this article, we shall look into some of the internals of IIS and then further proceed to communicate with IIS using WMI with VBScript.
You can execute every script by saving each of them individually as text files with the “.vbs” extension and execute through the WSH engine (like wscript.exe or cscript.exe) from your MS-DOS prompt.  Note that I tested all the scripts only with Windows Server 2003 Standard Edition.  
  Internals of IIS
  I don’t think there exists any web developer who doesn’t know IIS.  It is one of the most famous web servers available on the market.  It became quite famous with version 4.0 on Windows NT.  It was later upgraded to 5.0 on Windows 2000 and further enhanced to 6.0 on Windows 2003.  Version 7.0 is getting ready with Windows Vista!  Before proceeding with IIS 6.0, I would like to have a discussion about the internals of IIS 5.0.
  There was only one main process (or service) in IIS 5.0, represented by the executable inetinfo.exe that was designed to function as the main Web server process. This generally redirects requests to one or more out-of-process applications that are running within the “dllhost.exe”. The Inetinfo.exe is considered to be the master process through which each request must “penetrate” regardless of isolation mode.
  IIS 5.0 mainly has three isolation modes namely:
  In-Process,
Out-of-process
Pooled.
When considering the ”In-Process” mode, all the applications run in the same process as that of the Web server (inetinfo.exe). The IIS 5.0 default mode is “pooled,” in which the Web server (Inetinfo.exe) runs in its own process and all other applications will run in one single-pooled process (dllhost.exe). You can set high-priority applications to run as Isolated, which creates another instance of dllhost.exe (which also burdens RAM).
  Even though this out-of-process isolation allows you to increase the fault-tolerance of your Web server, it is slow in terms of performance. The Pooled mode is the best performance/isolation tradeoff, but there is only one pool on a server and all pooled applications must use the same pool.
  
Next: What is new in IIS 6.0? >>
  IIS 6.0, Getting Information Using WMI - What is new in IIS 6.0?
(Page 2 of 5 )
  
  IIS 6.0 is the next generation of Web server available in the Windows Server 2003 platform. IIS 6.0 obviously provides several enhancements over IIS 5.0 that are mainly intended to increase reliability, manageability, scalability, and security. IIS 6.0 is a key component of the Windows Server 2003 application platform, using which you can develop and deploy high performance ASP.NET Web applications, and XML Web Services.  XML Web Services can be natively deployed and we can even convert IIS6.0 to be UDDI directory!
  IIS 6.0 has been totally redesigned with a new request processing architecture that has the benefits of high isolation without incurring the out-of-process cost, as well as much higher levels of reliability and scalability.  Let us go through some of the main components of IIS6.0.
  HTTP.SYS
Web Administration Service
Application Pool
Worker Process
HTTP.SYS is a kernel-mode (OS level) HTTP listener that listens for incoming requests and queues those requests up on the appropriate queue. Kernel mode support is not available in IIS 5.0.  Each request will be serviced by one application pool. An application pool in IIS 6.0 can contain one or more applications.
  Web Administration Service is a user-mode configuration and process manager. The Web Administration Service component performs mainly Configuration and Process Management. When the Web server is first initialized, the Web Administration Service configures HTTP.SYS and the application pools (more about it later). It is also responsible for monitoring and controlling the lifetime of the worker processes (more about this later).
  Application pools are used to manage a set of websites and applications. IIS 6.0 can support up to 2,000 application pools per server, and there can be multiple application pools operating at the same time. Application pools are separated from other application pools by Windows Server 2003 process boundaries. Therefore, an application in one application pool is not affected by applications in other application pools, and an application request cannot be routed to another application pool while being serviced by the current application pool.
  A worker process services requests for the websites and applications in an application pool. All Web application processing, including loading of ISAPI filters and extensions, as well as authentication and authorization, is done by a new WWW service DLL, which is loaded into one or more host worker processes. The worker process executable is named W3WP.EXE.
  
Next: Can we retrieve IIS information using WMI? >>
IIS 6.0, Getting Information Using WMI - Can we retrieve IIS information using WMI?
(Page 3 of 5 )
  
  Why not? As WMI is also meant for system administration, obviously it boasts very good support for IIS.  To find more information about WMI, you can refer to my previous articles at this website.  To work with IIS and WMI together, we need to work with the classes existing in the “root\MicrosoftIISv2” namespace.  This is a very important point to remember when working with WMI for IIS.
  strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM IIsWebInfo",,48)
For Each objItem in colItems
    Wscript.Echo objItem. MajorIIsVersionNumber & " -->: " & objItem. MinorIIsVersionNumber
Next
  Within the above example, I am working with a class “IIsWebInfo” available in the “\\root\MicrosoftIISv2” namespace.  “IIsWebInfo” mainly contains all information regarding version, status, install date, and so on.
  Can we know, whether IIS is running or not using WMI? Certainly.  Not only that, we can even retrieve further information about IIS (if it is still running) by using the following script:
  strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM IIsWebService",,48)
For Each objItem in colItems
    Wscript.Echo "DisplayName: " & objItem.DisplayName
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PathName: " & objItem.PathName
    Wscript.Echo "Started: " & objItem.Started
    Wscript.Echo "State: " & objItem.State
    Wscript.Echo "Status: " & objItem.Status
    Wscript.Echo "SystemName: " & objItem.SystemName
Next
  Within the above example, I am working with a class “IIsWebService” available in the “\\root\MicrosoftIISv2” namespace.  “IIsWebService” gives more in-depth information than “IIsWebInfo”.
  
Next: Playing with Virtual directories and Web applications >>
IIS 6.0, Getting Information Using WMI - Playing with Virtual directories and Web applications
(Page 4 of 5 )
  
  Let us consider that I would like to retrieve all Virtual directories existing in my local IIS web server.  You can simply use the following WMI script and get it executed through WSH at the command prompt:
  strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM IIsWebVirtualDir",,48)
For Each objItem in colItems
    Wscript.Echo objItem.AppRootEcho & " --> " & objItem.Name
Next
  Within the above example, I am working with a class “IIsWebVirtualDir” available in  the “\\root\MicrosoftIISv2” namespace.  “IIsWebVirtualDir” mainly contains all directories, which are termed Virtual Directories.  You can get plenty of other information using the same class.
  If we wanted to know which web applications are currently running, along with their responsible application pools (as explained in second section), we can use the following script:
  strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM IIsWebVirtualDirSetting",,48)
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name & " -> Pool: " & objItem.AppPoolId
Next
  Within the above example, I am working with a class “IIsWebVirtualDirSetting” available in the “\\root\MicrosoftIISv2” namespace.  “IIsWebVirtualDirSetting” gets all the web settings or IIS settings for each and every Virtual Directory available in “IIsWebVirtualDir”.  The next example is also based on the same class.
  If you wanted to check and see all the virtual directories allowed with directory access, you have the following script:
  strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM IIsWebVirtualDirSetting",,48)
For Each objItem in colItems
        Wscript.Echo "Name: " & objItem.Name
& " -> browsing Enabled: " & objItem.EnableDirBrowsing
Next
  
Next: How about SMTP, POP3, FTP services in IIS? >>
IIS 6.0, Getting Information Using WMI - How about SMTP, POP3, FTP services in IIS?
(Page 5 of 5 )
  
  Any IIS being used for production would generally have one or more of SMTP, POP3, or FTP services enabled.  WMI can still help us retrieve information even to that level. The main information about the “status” of those services can be known using the classes “IISSmtpService”, “IISFtpService” and “IISPOP3Service” classes respectively.  Let us consider a few more scripts with respect to those services.
  Let us see if SMTP was enabled in IIS (using WMI).  The following is the code:
  strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM IIsSmtpService",,48)
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name & " -> running: " & objItem.Started
Next
  Let us see if FTP was enabled in IIS (using WMI).  The following is the code:
  strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM IIsFtpService",,48)
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name & " -> running: " & objItem.Started
Next
  Let us see if POP3 was enabled in IIS (using WMI).  The following is the code:
  strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM IIsPop3Service",,48)
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name & " -> running: " & objItem.Started
Next
  And that is that.
  
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-98779-1-1.html 上篇帖子: PHP5.3.6的IIS配置 下篇帖子: IIS 7.0、IIS 7.5 和 IIS 8.0 中的 HTTP 状态代码 转
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表