熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

用C#+WMI獲取w3wp進程對應的程序池

2022-06-13   來源: .NET編程 
    自從用了ASPNET以後這個問題被漸漸關注起來目前的方法就是調用iisappvbs獲取
  今天准備在我的文本轉換工具裡集成這個功能於是用C#實現了一下
  
  using System;
  using SystemText;
  using SystemTextRegularExpressions;
  using SystemDiagnostics;
  using SystemManagement;
  using SystemWindowsForms;
  
  namespace TextConvertor
  {
   /**//// <summary>
   /// Wwp 的摘要說明
   /// </summary>
   public class Wwp
   {
   private Wwp(){}
   public static string GetAllWwp(string input)
   {
   ObjectQuery oQuery = new ObjectQuery(select * from Win_Process where Name=wwpexe);
   ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oQuery);
   ManagementObjectCollection oReturnCollection = oSearcherGet();
  
   string pid;
   string cmdLine;
   StringBuilder sb = new StringBuilder() ;
   foreach(ManagementObject oReturn in oReturnCollection)
   {
   pid = oReturnGetPropertyValue(ProcessId)ToString();
   cmdLine = (string)oReturnGetPropertyValue(CommandLine);
  
   string pattern = ap \(*)\ ;
   Regex regex = new Regex(pattern RegexOptionsIgnoreCase) ;
   Match match = regexMatch(cmdLine) ;
   string appPoolName = matchGroups[]ToString() ;
   sbAppendFormat(WWPexe PID: {} AppPoolId:{}\r\n pid appPoolName );
   }
  
   return sbToString();
   }
   }
  }
  
  實現的原理和VBScript簡直一模一樣
  

From:http://tw.wingwit.com/Article/program/net/201311/12911.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.