淺談C#調(diào)用iisapp.vbs
作者:佚名
這里介紹目前的方法就是C#調(diào)用iisapp.vbs獲取。今天準(zhǔn)備在我的文本轉(zhuǎn)換工具里集成這個功能,于是,實(shí)現(xiàn)C#調(diào)用iisapp.vbs。
自從用了ASP.NET2.0以后,這個問題被漸漸關(guān)注起來,目前的方法就是C#調(diào)用iisapp.vbs獲取。今天準(zhǔn)備在我的文本轉(zhuǎn)換工具里集成這個功能,于是,實(shí)現(xiàn)C#調(diào)用iisapp.vbs。
C#調(diào)用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();
- }
- }
- }
【編輯推薦】
責(zé)任編輯:佚名
來源:
MSDN社區(qū)