自从用了ASP.NET2.0以后,这个问题被渐渐关注起来,目前的方法就是C#调用iisapp.vbs获取。今天准备在我的文本转换工具里集成这个功能,于是,实现C#调用iisapp.vbs。

创新互联是一家专业提供庆安企业网站建设,专注与网站设计制作、做网站、H5建站、小程序制作等业务。10年已为庆安众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。
C#调用iisapp.vbs代码:
- usingSystem;
 - usingSystem.Text;
 - usingSystem.Text.RegularExpressions;
 - usingSystem.Diagnostics;
 - usingSystem.Management;
 - usingSystem.Windows.Forms;
 - namespaceTextConvertor
 - {
 - /**////
 - ///W3wp的摘要说明。
 - ///
 - 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();
 - }
 - }
 - }