自從用了asp.net2.0以后,這個(gè)問(wèn)題被漸漸關(guān)注起來(lái),目前的方法就是調(diào)用iisapp.vbs獲取。
今天準(zhǔn)備在我的文本轉(zhuǎn)換工具里集成這個(gè)功能,于是,用C#實(shí)現(xiàn)了一下。
using System;
using System.Text;
using System.Text.RegularExPRessions;
using System.Diagnostics;
using System.Management;
using System.Windows.Forms;
namespace TextConvertor
{
/**//// <summary>
/// W3wp 的摘要說(shuō)明。
/// </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();
}
}
}
實(shí)現(xiàn)的原理和VBScript簡(jiǎn)直一模一樣。
http://www.survivalescaperooms.com/karoc/archive/2006/11/24/571245.html
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注