C#练习Array.Sort函数列出所有的进程与模块

 

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Collections;

namespace ICompare测试
{
    class Program
    {
        static void Main(string[] args)
        {
            Process[] allprocess = Process.GetProcesses();//所有运行的进程
            SortByProcessName cmpproname=new SortByProcessName();
            SortByModuleName cmpmodulename=new SortByModuleName();
            Array.Sort(allprocess, cmpproname);
            foreach (Process p in allprocess)
            {
                Console.WriteLine("{0}", p.ProcessName);
                try
                {

                    ProcessModuleCollection allmodules = p.Modules;//进程下的所有模块
                    ProcessModule[] modules = new ProcessModule[allmodules.Count];
                    int i = 0;
                    foreach (ProcessModule m in allmodules)
                    {
                        modules.SetValue(m, i++);
                    }
                    Array.Sort(modules, cmpmodulename);
                    foreach (ProcessModule m in modules)
                    {
                        try
                        {
                            Console.WriteLine("  {0}", m.ModuleName);
                        }
                        catch { continue; }
                    }
                }
                catch
                { }

            }
        }
    }
    public class SortByProcessName : IComparer//Array.Sort()要用到的参数
    {
        public int Compare(object x, object y)
        {
            Process a = (Process)x;
            Process b = (Process)y;
            return a.ProcessName.CompareTo(b.ProcessName);
        }
    }
    public class SortByModuleName : IComparer
    {

        public int Compare(object x, object y)
        {
            ProcessModule a = (ProcessModule)x;
            ProcessModule b = (ProcessModule)y;
            return a.ModuleName.CompareTo(b.ModuleName);
        }
    }
}

 

结果:

  MSIMG32.dll
  msvcrt.dll
  MSVFW32.dll
  MSWSOCK.dll
  ncrypt.dll
  NETAPI32.dll
  netutils.dll
  npmproxy.dll
  NSI.dll
  ntdll.dll
  ntmarta.dll
  ole32.dll
  OLEAUT32.dll
  POWRPROF.dll
  profapi.dll
  propsys.dll
  PSAPI.DLL
  RICHED20.DLL
  RPCRT4.dll
  RpcRtRemote.dll
  rsaenh.dll
  safemon.dll
  SAMCLI.DLL
  sechost.dll
  Secur32.dll
  SensApi.dll
  SETUPAPI.dll
  SHELL32.dll
  SHLWAPI.dll
  slc.dll
  srvcli.dll
  SspiCli.dll
  TeamViewer.exe
  TeamViewer_Resource_zhCN.dll
  TeamViewer_StaticRes.dll
  tv_w32.dll
  urlmon.dll
  USER32.dll
  USERENV.dll
  USP10.dll
  uxtheme.dll
  VERSION.dll
  wdmaud.drv
  webio.dll
  winhttp.dll
  WININET.dll
  WINMM.dll
  WINNSI.DLL
  winsta.dll
  WINTRUST.dll
  wkscli.dll
  WLDAP32.dll
  WS2_32.dll
  wshtcpip.dll
  WTSAPI32.dll
TeamViewer_Service
  ADVAPI32.dll
  apphelp.dll
  bcrypt.dll
  bcryptprimitives.dll
  browcli.dll
  CFGMGR32.dll
  CLBCatQ.DLL
  comctl32.dll
  CRYPT32.dll
  CRYPTBASE.dll
  CRYPTSP.dll
  cscapi.dll
  d3d8thk.dll
  d3d9.dll
  davclnt.dll
  DAVHLPR.dll
  DEVOBJ.dll
  dhcpcsvc.DLL
  DNSAPI.dll
  drprov.dll
  dwmapi.dll
  fastprox.dll
  fwpuclnt.dll
  GDI32.dll
  gdiplus.dll
  GPAPI.dll
  iertutil.dll
  imagehlp.dll
  IMM32.DLL
  IPHLPAPI.DLL
  kernel32.dll
  KERNELBASE.dll
  LPK.dll
  Magnification.dll
  MPR.dll
  MSASN1.dll
  MSCTF.dll
  msvcrt.dll
  MSWSOCK.dll
  napinsp.dll
  ncrypt.dll
  Netapi32.dll
  netprofm.dll
  netutils.dll
  NLAapi.dll
  Normaliz.dll
  npmproxy.dll
  NSI.dll
  ntdll.dll
  NTDSAPI.dll
  ntlanman.dll
  ntmarta.dll
  ole32.dll
  OLEAUT32.dll
  pnrpnsp.dll
  profapi.dll
  propsys.dll
  Psapi.dll
  rasadhlp.dll
  RASAPI32.dll
  rasman.dll
  RPCRT4.dll
  RpcRtRemote.dll
  rsaenh.dll
  rtutils.dll
  sechost.dll
  Secur32.dll
  SensApi.dll
  SETUPAPI.dll
  SHELL32.dll
  SHLWAPI.dll
  srvcli.dll
  SspiCli.dll
  SXS.DLL
  TeamViewer_Service.exe
  urlmon.dll
  USER32.dll
  USERENV.dll
  USP10.dll
  uxtheme.dll
  VERSION.dll
  wbemcomn.dll
  wbemprox.dll
  wbemsvc.dll
  WININET.dll
  WINNSI.DLL
  winrnr.dll
  winsta.dll
  WINTRUST.dll
  wkscli.dll
  WLDAP32.dll
  WS2_32.dll
  wshbth.dll
  wship6.dll
  wshtcpip.dll
  WTSAPI32.dll
TSVNCache
tv_w32
  ADVAPI32.dll
  CFGMGR32.dll
  COMCTL32.dll
  CRTDLL.dll
  CRYPTBASE.dll
  DEVOBJ.dll
  devrtl.DLL
  GDI32.dll
  IMM32.DLL
  kernel32.dll
  KERNELBASE.dll
  LPK.dll
  MSCTF.dll
  msvcrt.dll
  newdev.dll
  ntdll.dll
  ole32.dll
  OLEAUT32.dll
  RPCRT4.dll
  sechost.dll
  setupapi.dll
  SHELL32.dll
  SHLWAPI.dll
  SspiCli.dll
  tv_w32.dll
  tv_w32.exe
  USER32.dll
  USP10.dll
  UxTheme.dll
tv_x64
TXPlatform
  ADVAPI32.dll
  CLBCatQ.DLL
  COMCTL32.dll
  CRTDLL.dll
  CRYPT32.dll
  CRYPTBASE.dll
  CRYPTSP.dll
  GDI32.dll
  iertutil.dll
  IMM32.DLL
  kernel32.dll
  KERNELBASE.dll
  LPK.dll
  MSASN1.dll
  MSCTF.dll
  msvcrt.dll
  NSI.dll
  ntdll.dll
  ole32.dll
  OLEAUT32.dll
  PSAPI.DLL
  RPCRT4.dll
  RpcRtRemote.dll
  rsaenh.dll
  safemon.dll
  sechost.dll
  SHELL32.dll
  SHLWAPI.dll
  SspiCli.dll
  SXS.DLL
  tv_w32.dll
  TXPFProxy.dll
  TXPlatform.exe
  urlmon.dll
  USER32.dll
  USP10.dll
  uxtheme.dll
  VERSION.dll
  WININET.dll
  WINTRUST.dll
  WS2_32.dll
wininit
winlogon
ZhuDongFangYu
  360base.dll
  360conf.dll
  360leakfixplugin.dll
  360NetBase.dll
  360SoftMgrS.dll
  ADVAPI32.dll
  apphelp.dll
  CFGMGR32.dll
  CLBCatQ.DLL
  cloudcom2.dll
  COMCTL32.dll
  CRYPT32.dll
  CRYPTBASE.dll
  DEVOBJ.dll
  dhcpcsvc.DLL
  dhcpcsvc6.DLL
  DNSAPI.dll
  fltlib.dll
  GDI32.dll
  heavygate.dll
  iertutil.dll
  IMM32.DLL
  IPHLPAPI.DLL
  kernel32.dll
  KERNELBASE.dll
  LINKINFO.dll
  LPK.dll
  MSASN1.dll
  MSCTF.dll
  mstask.dll
  msvcrt.dll
  mswsock.dll
  NETAPI32.dll
  netutils.dll
  NSI.dll
  ntdll.dll
  ole32.dll
  OLEAUT32.dll
  profapi.dll
  propsys.dll
  PSAPI.DLL
  qutmload.dll
  RASAPI32.dll
  rasman.dll
  RPCRT4.dll
  RpcRtRemote.dll
  rtutils.dll
  SAMCLI.DLL
  SAMLIB.dll
  sechost.dll
  secur32.dll
  SETUPAPI.dll
  SHELL32.dll
  SHLWAPI.dll
  srvcli.dll
  SspiCli.dll
  taskschd.dll
  urlmon.dll
  USER32.dll
  USERENV.dll
  USP10.dll
  VERSION.dll
  WININET.dll
  WINMM.dll
  WINNSI.DLL
  WINTRUST.dll
  wkscli.dll
  WS2_32.dll
  WTSAPI32.dll
  zhudongfangyu.exe
请按任意键继续. . .

时间: 2024-09-05 11:29:27

C#练习Array.Sort函数列出所有的进程与模块的相关文章

JavaScript中sort函数

JavaScript中sort函数方法是返回一个元素已经进行了排序的 Array 对象. 使用方法: arrayobj.sort(sortfunction) 其中arrayObj是必选项.任意 Array 对象. sortFunction是可选项.是用来确定元素顺序的函数的名称.如果这个参数被省略,那么元素将按照 ASCII 字符顺序进行升序排列. JavaScript中sort函数方法将 Array 对象进行适当的排序:在执行过程中并不会创建新的 Array 对象. 如果为 sortfunct

js数组Array sort方法使用深入分析_javascript技巧

javascript 中 Array.sort()方法是用来对数组项进行排序的 ,默认情况下是进行升序排列,实例代码如下: 复制代码 代码如下: var arrA = [6,2,4,3,5,1]; arrA.sort(); document.writeln(arrA); //结果是:1,2,3,4,5,6 sort() 方法可以接受一个 方法为参数 ,这个方法有两个参数.分别代表每次排序比较时的两个数组项.sort()排序时每次比较两个数组项都回执行这个参数,并把两个比较的数组项作为参数传递给这

JS数组(Array)处理函数总结

原文:JS数组(Array)处理函数总结 1.concat() 连接两个或更多的数组该方法不会改变现有的数组,而仅仅会返回被连接数组的一个副本.例如: 1 <script type="text/javascript"> 2 var arr = [1, 2, 3]; 3 var arr1 = [11, 22, 33]; 4 document.write(arr.concat(4, 5, arr1)); 5 </script> 输出结果:1,2,3,4,5,11,2

php通过sort()函数给数组排序的方法_php技巧

本文实例讲述了php通过sort()函数给数组排序的方法.分享给大家供大家参考.具体分析如下: sort()函数用于给数组排序,本函数为数组中的单元赋予新的键名.原有的键名将被删除. 如果成功则返回 TRUE,否则返回 FALSE. $alpha = array ("x", "a", "f", "c"); sort( $alpha ); foreach ( $alpha as $var ) { print "$var

php数组排序usort、uksort与sort函数用法_php技巧

本文实例讲述了php数组排序usort.uksort与sort函数用法.分享给大家供大家参考.具体用法分析如下: 对数组排序:usort() 函数使用用户自定义的函数对数组排序,实例代码如下: 复制代码 代码如下: function cmp($a, $b)        //用户自定义回调函数 {   if($a==$b)         //如果两个参数相等   {     return 0;         //返回0   }   return($a>$b)?-1:1;       //如果

linux内核中的排序接口--sort函数

linux内核中的sort函数,其实跟我们所说的qsort函数很像,我们来看看qsort: qsort 的函数原型是 void qsort(void*base,size_t num,size_t width,int(__cdecl*compare)(const void*,const void*)); 参数:  1 .待排序数组首地址 2 .数组中待排序元素数量 3 .各元素的占用空间大小 4 .指向函数的指针,用于确定排序的顺序. 其中compare函数应写为: 1 2 3 4 int com

Perl Sort函数用法总结和使用实例_应用技巧

一) sort函数用法 sort LISTsort BLOCK LISTsort SUBNAME LIST sort的用法有如上3种形式.它对LIST进行排序,并返回排序后的列表.假如忽略了SUBNAME或BLOCK,sort按标准字串比较顺序来进行(例如ASCII顺序).如果指定了SUBNAME,它实际上是个子函数的名字,该子函数对比2个列表元素,并返回一个小于,等于,或大于0的整数,这依赖于元素以何种顺序来sort(升序,恒等,或降序).也可提供一个BLOCK作为匿名子函数来代替SUBNAM

浅析C/C++中sort函数的用法_C 语言

sort是STL中提供的算法,头文件为#include<algorithm>以及using namespace std; 函数原型如下: template <class RandomAccessIterator> void sort ( RandomAccessIterator first, RandomAccessIterator last ); template <class RandomAccessIterator, class Compare> void sor

php数组排序usort uksort sort函数

对数组排序 usort() 函数使用用户自定义的函数对数组排序. */ function cmp($a, $b)        //用户自定义回调函数 {   if($a==$b)         //如果两个参数相等   {     return 0;         //返回0   }   return($a>$b)?-1:1;       //如果第1个参数大于第2个返回1,否则-1 } $a=array(3,2,5,6,1);        //定义一个数组 usort ($a,"