自从用了ASP.NET2.0以后,这个问题被渐渐关注起来,目前的方法就是C#调用iisapp.vbs获取。今天准备在我的文本转换工具里集成这个功能,于是,实现C#调用iisapp.vbs。
C#调用iisapp.vbs代码:
- usingSystem;
- usingSystem.Text;
- usingSystem.Text.RegularExpressions;
- usingSystem.Diagnostics;
- usingSystem.Management;
- usingSystem.Windows.Forms;
- namespaceTextConvertor
- {
- /**////<summary>
- ///W3wp的摘要说明。
- ///</summary>
- publicclassW3wp
- {
- privateW3wp(){}
- publicstaticstringGetAllW3wp(stringinput)
- {
- ObjectQueryoQuery=newObjectQuery
("select*fromWin32_ProcesswhereName='w3wp.exe'");- ManagementObjectSearcheroSearcher=newManagementObjectSearcher(oQuery);
- ManagementObjectCollectionoReturnCollection=oSearcher.Get();
- stringpid;
- stringcmdLine;
- StringBuildersb=newStringBuilder();
- foreach(ManagementObjectoReturninoReturnCollection)
- {
- pid=oReturn.GetPropertyValue("ProcessId").ToString();
- cmdLine=(string)oReturn.GetPropertyValue("CommandLine");
- stringpattern="-ap\"(.*)\"";
- Regexregex=newRegex(pattern,RegexOptions.IgnoreCase);
- Matchmatch=regex.Match(cmdLine);
- stringappPoolName=match.Groups[1].ToString();
- sb.AppendFormat("W3WP.exePID:{0}AppPoolId:{1}\r\n",pid,appPoolName);
- }
- returnsb.ToString();
- }
- }
- }
【编辑推荐】