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

推荐订阅源

T
The Exploit Database - CXSecurity.com
J
Java Code Geeks
H
Help Net Security
B
Blog RSS Feed
G
Google Developers Blog
博客园 - 司徒正美
MongoDB | Blog
MongoDB | Blog
量子位
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
P
Proofpoint News Feed
小众软件
小众软件
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
V
V2EX
月光博客
月光博客
C
Check Point Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
A
Arctic Wolf
Help Net Security
Help Net Security
Schneier on Security
Schneier on Security
D
DataBreaches.Net
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Palo Alto Networks Blog
T
Tenable Blog
L
LangChain Blog
Attack and Defense Labs
Attack and Defense Labs
Google DeepMind News
Google DeepMind News
N
News and Events Feed by Topic
Forbes - Security
Forbes - Security
F
Fortinet All Blogs
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
大猫的无限游戏
大猫的无限游戏
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Y
Y Combinator Blog
WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
NISL@THU
NISL@THU
GbyAI
GbyAI
博客园 - Franky
S
Secure Thoughts
有赞技术团队
有赞技术团队
PCI Perspectives
PCI Perspectives
U
Unit 42

博客园 - 网际飞狐

异步服务框架 如何在TFS中用命令行提交更新 CollabNet Subversion 输出自定义日期格式 - 网际飞狐 - 博客园 你正确关闭WCF链接了吗? 通过OperationContext添加消息头信息 PHP在II7安装指南 [Google App Engine] Hello, world! 在IIS7中配置使用Python 2008年12月小记(NewSequentialID(),ADO.NET Data Service,Visual Studio Tips,安装Django,JQuery智能感知) [OpenAPI] html标签分析 System.Web.Routing 使用基础 Notes for 2008-11(GetRange, backup,file hash, PostRequest, QueryString) JS通过服务代理调用跨域服务 对硬编码WCF服务的封装(提供服务和客户端调用的封装,调用样例....) Observer Pattern, Delegate and Event 项目框架概要 2008年10月小记(SQL删除重复记录,生成表结构,字符串特性,statistics io) WinDbg使用摘要
How to view the W3WP process by c#?
网际飞狐 · 2008-10-21 · via 博客园 - 网际飞狐

   We need to know which w3wp process is running now When we debug my website in the Visual Studio. As we know, we can use this cmd(%windir%/system32/inetsrv/appcmd list wp) to show the result in the windows2008. But, How to view the W3WP process by c#?
I give the method to you, please look this code:

        static void Main(string[] args)
        {
            
string str = CmdListWP();
            Console.WriteLine(str);
            Console.WriteLine(
"Please press any key to exit!");
            Console.ReadLine();
        }
private static string CmdListWP()
        {
            Process p 
= new Process();
            p.StartInfo.FileName 
= "cmd.exe";                    //设定调用程序的名称
            p.StartInfo.UseShellExecute = false;                  //关闭Shell的使用
            p.StartInfo.RedirectStandardInput = true;         //重定向标准输入
            p.StartInfo.RedirectStandardOutput = true;      //重定向标准输出
            p.StartInfo.RedirectStandardError = true;          //重定向错误输出
            p.StartInfo.CreateNoWindow = true;                //配置不显示窗口

            
string output;
            p.Start();
            
try
            {
                p.StandardInput.WriteLine(
"%windir%/system32/inetsrv/appcmd list wp");
                p.StandardInput.WriteLine(
"exit");
                output 
= p.StandardOutput.ReadToEnd();
            }
            
finally
            {
                p.Close();
            }
string result = string.Empty;
            
if (output.IndexOf("WP \"") != -1) //是否有启动的站点
            {
                
//正则表达式提取
                
//for example: WP "29308" <applicationPool:profile3.csdn.net>
                string pattern = "WP \"\\d+\" .+";
                List
<string> list = new List<string>();
                Regex regex 
= new Regex(pattern);
                
if (regex.IsMatch(output))
                {
                    MatchCollection mc 
= regex.Matches(output);
                    
for (int i = 0; i < mc.Count; i++)
                    {
                        list.Add(mc[i].Value);
                    }
                }
                
foreach (string str in list)
                {
                    result 
+= str + "\n";
                }
            }
            
return result;
        }

Please take attention to the code: Process p = new Process();
we can use the Process object to run the cmd.exe process, and then run the "appcmd list wp" command. after it, we can receive the output string, and analyse the string to get the result of what we want to get.