惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - karoc

《重构-改善既有代码的设计》读书笔记 扩展GridView,增加单选按钮列 任务开始时间和完成时间 最大长度验证控件:MaxLengthValidator 又是关于AjaxControlToolkit的ModalPopup的问题 有个总结 使用svn的小插曲 开发小经验总结(不断更新) 今天发现一个VS2008中文版和英文版的差别 解决DocType引起AjaxTookit的ModulPopup显示异常问题的方法 Reporting Services 2005 常见问题解决方法(不断更新) - karoc 用VSTO开发Project插件心得 自定义MemberShipProvider和PersonalizationProvider使用WebParts实现个性化页面 - karoc 在线修改KeyValue配置节 瞎搞八搞,另类PageBase 改造Duwamish中的Configuration 直接用Response输出可以加批注的Excel C#控制Windows Messenger和Windows Live Messenger窗口发送消息 一个读取扩展名为xml的资源文件的方法
用C#+WMI实现获取w3wp进程对应的应用程序池
karoc · 2006-11-24 · via 博客园 - karoc

自从用了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();
        }

    }

}

实现的原理和VBScript简直一模一样。