国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

用C#+WMI實(shí)現(xiàn)獲取w3wp進(jìn)程對(duì)應(yīng)的應(yīng)用程序池

2019-11-18 16:51:49
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

自從用了asp.net2.0以后,這個(gè)問(wèn)題被漸漸關(guān)注起來(lái),目前的方法就是調(diào)用iisapp.vbs獲取。
今天準(zhǔn)備在我的文本轉(zhuǎn)換工具里集成這個(gè)功能,于是,用C#實(shí)現(xiàn)了一下。

using System;
using System.Text;
using System.Text.RegularExPRessions;
using System.Diagnostics;
using System.Management;
using System.Windows.Forms;

namespace TextConvertor
{
    /**//// <summary>
    /// W3wp 的摘要說(shuō)明。
    /// </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();
        }
    }
}

實(shí)現(xiàn)的原理和VBScript簡(jiǎn)直一模一樣。
http://www.survivalescaperooms.com/karoc/archive/2006/11/24/571245.html


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 洪洞县| 天柱县| 中卫市| 五华县| 五寨县| SHOW| 昌黎县| 卓资县| 泊头市| 班玛县| 民县| 金乡县| 宣城市| 崇信县| 全南县| 饶平县| 新源县| 大厂| 墨玉县| 库尔勒市| 五指山市| 崇义县| 芷江| 藁城市| 大洼县| 三亚市| 弥勒县| 宁河县| 东丰县| 霍山县| 枝江市| 噶尔县| 前郭尔| 贞丰县| 云龙县| 庆元县| 德令哈市| 凉城县| 二连浩特市| 桂林市| 龙里县|