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

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
D
DataBreaches.Net
量子位
C
Cybersecurity and Infrastructure Security Agency CISA
G
Google Developers Blog
小众软件
小众软件
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Cisco Talos Blog
Cisco Talos Blog
P
Proofpoint News Feed
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
T
Tenable Blog
Vercel News
Vercel News
AWS News Blog
AWS News Blog
Forbes - Security
Forbes - Security
M
MIT News - Artificial intelligence
S
Security Affairs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hacker News - Newest:
Hacker News - Newest: "LLM"
美团技术团队
L
Lohrmann on Cybersecurity
博客园 - 司徒正美
Last Week in AI
Last Week in AI
罗磊的独立博客
Project Zero
Project Zero
Cyberwarzone
Cyberwarzone
S
Schneier on Security
S
Secure Thoughts
T
Threatpost
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Y
Y Combinator Blog
F
Full Disclosure
N
Netflix TechBlog - Medium
博客园 - 叶小钗
A
Arctic Wolf
腾讯CDC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
The Exploit Database - CXSecurity.com
Jina AI
Jina AI
Apple Machine Learning Research
Apple Machine Learning Research
C
Check Point Blog
C
CERT Recently Published Vulnerability Notes
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - karoc

《重构-改善既有代码的设计》读书笔记 扩展GridView,增加单选按钮列 任务开始时间和完成时间 最大长度验证控件:MaxLengthValidator 又是关于AjaxControlToolkit的ModalPopup的问题 有个总结 使用svn的小插曲 开发小经验总结(不断更新) 今天发现一个VS2008中文版和英文版的差别 解决DocType引起AjaxTookit的ModulPopup显示异常问题的方法 Reporting Services 2005 常见问题解决方法(不断更新) 用VSTO开发Project插件心得 自定义MemberShipProvider和PersonalizationProvider使用WebParts实现个性化页面 在线修改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简直一模一样。