C#练习Array.Sort函数列出所有的进程与模块-阿里云开发者社区

开发者社区> 真爱无限> 正文

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

简介:     using System; using System.Collections.Generic; using System.Text; using System.
+关注继续查看

 

 

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
请按任意键继续. . .

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
linux strace-跟踪进程的系统调用或是信号产生情况,lstrace-跟踪己丑年调用库函数情况,进程跟踪调试命令
本工具可以用来做大多数排除,比如mount一个NFS,很慢,找不出原因,我们可以使用strace命令来跟中mount这个经常所有的调用过程。 strace 命令是一种强大的工具,它能够显示所有由用户空间程序发出的系统调用。
1353 0
阿里云服务器端口号设置
阿里云服务器初级使用者可能面临的问题之一. 使用tomcat或者其他服务器软件设置端口号后,比如 一些不是默认的, mysql的 3306, mssql的1433,有时候打不开网页, 原因是没有在ecs安全组去设置这个端口号. 解决: 点击ecs下网络和安全下的安全组 在弹出的安全组中,如果没有就新建安全组,然后点击配置规则 最后如上图点击添加...或快速创建.   have fun!  将编程看作是一门艺术,而不单单是个技术。
4623 0
Python之sort()函数详解
#从小到大排列 print(sorted([36, 5, -12, 9, -21])) #将待排序的值放入到key中的函数中,在进行比较排序 print(sorted([36, 5, -12, 9, -21], key=abs)) #字符串排序 : 通过ASCII方式比较第...
764 0
与进程联系的文件系统相关结构
进程是通过文件描述符(file descriptor,fd)来访问文件的,每个进程最多能同时使用NR_OPEN个文件描述符,这个值在include/linux/limits.h中定义为1024。每一个进程用一个打开文件表files_struct来描述进程的文件描述符使用情况。
600 0
Spring MVC 函数式编程进阶
1. 前言 上一篇对 Spring MVC 的函数式接口编程进行了简单入门,让很多不知道的同学见识了这种新操作。也有反应这种看起来没有传统写法顺眼,其实大家都一样。但是我们还是要敢于尝试新事物。Java Lambada 刚出来也是被人各种吐槽,现在我在很多项目都见到了它的身影。好了转回正题,本文是对上一篇的延伸,我们继续对 Functional Endpoint 进行一些了解和运用。范式转换其实上一篇已经介绍差不多了,但是一旦你初次接触这种方式往往会面临新的问题。 2. 新的问题 在使用这种风格时我们也会遇到一些新的问题。接下来我们将通过举例来一步步解决这些问题。 2.1 如何异常处理 接
26 0
Android 进程生命周期 Process Lifecycle
  进程的生命周期   Android系统会尽力保持应用的进程,但是有时为了给新的进程和更重要的进程回收一些内存空间,它会移除一些旧的进程。
634 0
+关注
真爱无限
主要技术.net sqlserver mysql。
302
文章
1
问答
文章排行榜
最热
最新
相关电子书
更多
文娱运维技术
立即下载
《SaaS模式云原生数据仓库应用场景实践》
立即下载
《看见新力量:二》电子书
立即下载