自从用了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简直一模一样。
posted @ 2006-11-24 17:44 karoc 阅读(758) 评论(0) 编辑
1、虚拟目录批量创建工具
以前一个解决方案下有n个虚拟目录,这个还挺管用的(下载

2、SQL Command File生成器
部署、更新数据库的时候可以用,把n个sql脚本文件生成一个cmd文件和一个bat文件,有ClickOnce的效果哦 ^-^(下载

3、ASP.NET发布器
基本就是一个拷贝目录下文件到另一个目录的工具,以前发布的时候,还帮了不少忙呢(下载

4、Messenger助手
Windows Messenger和MSN/WLM上有不少联系人,用这个工具可以群发消息哦,当然也可以帮你把想聊天的人一下都加进来,自己想说什么就说什么(下载


需要源码的同志,请从这里下载

posted @ 2006-11-24 09:22 karoc 阅读(255) 评论(2) 编辑