zoukankan      html  css  js  c++  java
  • 用C#+WMI实现获取w3wp进程对应的应用程序池

    作者: AspCool   www.ASPCool.com 时间:2006-12-12 21:06:22  阅读次数:2392

         自从用了ASP.NET2.0以后,这个问题被渐渐关注起来,目前的方法就是调用iisapp.vbs获取。
      今天准备在我的文本转换工具里集成这个功能,于是,用C#实现了一下。
      
      using System;
      using System.Text;
      using System.Text.RegularExpressions;
      using System.Diagnostics;
      using System.Management;
      using System.Windows.Forms;
      
      namespace TextConvertor
      {
       /**//// <summary>
       /// W3wp 的摘要说明。
       /// </summary>
       public class W3wp
       {
       private W3wp(){}
       public static string GetAllW3wp(string input)
       {
       ObjectQuery oQuery = new ObjectQuery("select * from Win32_Process where Name='w3wp.exe'");
       ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oQuery);
       ManagementObjectCollection oReturnCollection = oSearcher.Get();
      
       string pid;
       string cmdLine;
       StringBuilder sb = new StringBuilder() ;
       foreach(ManagementObject oReturn in oReturnCollection)
       {
       pid = oReturn.GetPropertyValue("ProcessId").ToString();
       cmdLine = (string)oReturn.GetPropertyValue("CommandLine");
      
       string pattern = "-ap \"(.*)\"" ;
       Regex regex = new Regex(pattern, RegexOptions.IgnoreCase) ;
       Match match = regex.Match(cmdLine) ;
       string appPoolName = match.Groups[1].ToString() ;
       sb.AppendFormat("W3WP.exe PID: {0} AppPoolId:{1}\r\n", pid, appPoolName );
       }
      
       return sb.ToString();
       }
       }
      }
  • 相关阅读:
    encodeURIComponent与encodeURI的区别
    css实现强制不换行/自动换行/强制换行
    浏览器的visibilitychange 事件ie10以下不兼容
    判断IE版本的语句 [if lte IE 6]...[endif]
    jQueryr .on方法解析
    js判断IE6(推荐方法一)
    JS判断设备终端(PC,iPad,iPhone,android,winPhone)和浏览器
    js判断手机浏览器
    js数字格式化-四舍五入精简版
    jQuery scroll(滚动)延迟加载
  • 原文地址:https://www.cnblogs.com/meiproject/p/1090284.html
Copyright © 2011-2022 走看看