zoukankan      html  css  js  c++  java
  • Atitit,通过pid获取进程文件路径 java php  c#.net版本大总结

    Atitit,通过pid获取进程文件路径 java php  c#.net版本大总结

     

     

    1通过PID获取进程路径的几种方法2

    1.1. GetModuleFileNameEx 想获得进程可执行文件的路径最常用的方法是通过GetModuleFileNameEx函数获得可执行文件的模块路径这个函数从Windows NT 4.0开始到现在的Vista系统都能使用,向后兼容性比较好。2

    1.2. 第二种方法是GetProcessImageFileName函数,这个函数在Windows XP及其以后的系统中都能使用,使用此函数返回的路径不是通常的系统盘符,如"C:\...",而是驱动层的表示方式"\Device\HarddiskVolume1\...",所以使用起来不是很方便。2

    1.3. 第三种方法是使用Windows Vista新增的函数QueryFullProcessImageName,由于是Vista新增的,所以兼容性不好。2

    2使用powershell  相等于调用System.Diagnostics.Process2

    2.1. Get-Process -id 6712 -FileVersionInfo2

    2.1.1. -FileVersionInfo3

    2.2. C#.net版本3

    2.3. Note3

    3获取加载的dll模块列表    Get-Process -id 6712 -Module3

    4参考10

     

     

    1. 通过PID获取进程路径的几种方法

    1.1. GetModuleFileNameEx
    想获得进程可执行文件的路径最常用的方法是通过GetModuleFileNameEx函数获得可执行文件的模块路径这个函数从Windows NT 4.0开始到现在的Vista系统都能使用,向后兼容性比较好。

    1.2. 第二种方法是GetProcessImageFileName函数,这个函数在Windows XP及其以后的系统中都能使用,使用此函数返回的路径不是通常的系统盘符,如"C:\...",而是驱动层的表示方式"\Device\HarddiskVolume1\...",所以使用起来不是很方便。

    1.3. 第三种方法是使用Windows Vista新增的函数QueryFullProcessImageName,由于是Vista新增的,所以兼容性不好。

     

    2. 使用powershell  相等于调用System.Diagnostics.Process

    2.1.  Get-Process -id 6712 -FileVersionInfo 

     

     

    PS C:\Windows\winsxs\amd64_microsoft-windows-gpowershell-exe_31bf3856ad364e35_6.1.7600.16385_none_94861149bb66249c>  Get-Process -id 6712 -FileVersionInfo 

     

    ProductVersion   FileVersion      FileName                                                                                                                                                                                                                                                                               

    --------------   -----------      --------                                                                                                                                                                                                                                                                               

                                      C:\eclipse\eclipse.exe        

     

     

     

     

     

    2.1.1. -FileVersionInfo 

    获取进程中运行的程序的文件版本信息。

    在 Windows Vista 以及更高版本的 Windows 上,必须使用“以管理员身份运行”选项打开 Windows PowerShell,才能对您不具有所有权的进程使用此参数。

    使用此参数等效于获取每个进程对象的 MainModule.FileVersionInfo 属性。如果使用此参数,则 Get-Process 返回 FileVersionInfo 对象 (System.Diagnostics.FileVersionInfo),而非进程对象。因此,不能通过管道将命令输出传递到需要进程对象的 cmdlet(例如 Stop-Process)。

     

     

    作者:: 绰号:老哇的爪子 ( 全名::Attilax akbar al rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙,  EMAIL:1466519819@qq.com

     

    2.2. C#.net版本

    //根据名称获取进程
    Process[] ps = Process.GetProcessesByName("NameStr");
    foreach (Process p in ps)
    {
    //输出进程路径
    Console.WriteLine(p.MainModule.FileName);
    }

     

    2.3. Note

    需要先设置权限RemoteSigned前面有空格与set-ExecutionPolicy 隔开

    set-ExecutionPolicy        RemoteSigned

    3. 获取加载的dll模块列表    Get-Process -id 6712 -Module  

     

    PS C:\Windows\winsxs\amd64_microsoft-windows-gpowershell-exe_31bf3856ad364e35_6.1.7600.16385_none_94861149bb66249c>  Get-Process -id 6712 -Module  

     

       Size(K) ModuleName                                         FileName                                                                                                                                                                                                                                                   

       ------- ----------                                         --------                                                                                                                                                                                                                                                   

           316 eclipse.exe                                        C:\eclipse\eclipse.exe                                                                                                                                                                                                                                     

          1700 ntdll.dll                                          C:\Windows\SYSTEM32\ntdll.dll                                                                                                                                                                                                                              

          1152 kernel32.dll                                       C:\Windows\system32\kernel32.dll                                                                                                                                                                                                                           

           432 KERNELBASE.dll                                     C:\Windows\system32\KERNELBASE.dll                                                                                                                                                                                                                         

          1000 USER32.dll                                         C:\Windows\system32\USER32.dll                                                                                                                                                                                                                             

           412 GDI32.dll                                          C:\Windows\system32\GDI32.dll                                                                                                                                                                                                                              

            56 LPK.dll                                            C:\Windows\system32\LPK.dll                                                                                                                                                                                                                                

           808 USP10.dll                                          C:\Windows\system32\USP10.dll                                                                                                                                                                                                                              

           636 msvcrt.dll                                         C:\Windows\system32\msvcrt.dll                                                                                                                                                                                                                             

          2000 COMCTL32.dll                                       C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.18837_none_fa3b1e3d17594757\COMCTL32.dll                                                                                                                               

           452 SHLWAPI.dll                                        C:\Windows\system32\SHLWAPI.dll                                                                                                                                                                                                                            

           184 IMM32.DLL                                          C:\Windows\system32\IMM32.DLL                                                                                                                                                                                                                              

          1060 MSCTF.dll                                          C:\Windows\system32\MSCTF.dll                                                                                                                                                                                                                              

            72 eclipse_1608.dll                                   C:\eclipse\plugins\org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20150204-1316\eclipse_1608.dll                                                                                                                                                 

           876 ADVAPI32.dll                                       C:\Windows\system32\ADVAPI32.dll                                                                                                                                                                                                                           

           124 sechost.dll                                        C:\Windows\SYSTEM32\sechost.dll                                                                                                                                                                                                                            

          1204 RPCRT4.dll                                         C:\Windows\system32\RPCRT4.dll                                                                                                                                                                                                                             

            48 VERSION.dll                                        C:\Windows\system32\VERSION.dll                                                                                                                                                                                                                            

           344 uxtheme.dll                                        C:\Windows\system32\uxtheme.dll                                                                                                                                                                                                                            

          2060 ole32.dll                                          C:\Windows\system32\ole32.dll                                                                                                                                                                                                                              

            60 CRYPTBASE.dll                                      C:\Windows\system32\CRYPTBASE.dll                                                                                                                                                                                                                          

          8552 jvm.dll                                            C:\eclipse\jre\bin\server\jvm.dll                                                                                                                                                                                                                          

            36 WSOCK32.dll                                        C:\Windows\system32\WSOCK32.dll                                                                                                                                                                                                                            

           308 WS2_32.dll                                         C:\Windows\system32\WS2_32.dll                                                                                                                                                                                                                             

            32 NSI.dll                                            C:\Windows\system32\NSI.dll                                                                                                                                                                                                                                

           236 WINMM.dll                                          C:\Windows\system32\WINMM.dll                                                                                                                                                                                                                              

            28 PSAPI.DLL                                          C:\Windows\system32\PSAPI.DLL                                                                                                                                                                                                                              

           840 MSVCR100.dll                                       C:\Windows\system32\MSVCR100.dll                                                                                                                                                                                                                           

            60 verify.dll                                         C:\eclipse\jre\bin\verify.dll                                                                                                                                                                                                                              

           160 java.dll                                           C:\eclipse\jre\bin\java.dll                                                                                                                                                                                                                                

            88 zip.dll                                            C:\eclipse\jre\bin\zip.dll                                                                                                                                                                                                                                 

         13860 SHELL32.dll                                        C:\Windows\system32\SHELL32.dll                                                                                                                                                                                                                            

            60 profapi.dll                                        C:\Windows\system32\profapi.dll                                                                                                                                                                                                                            

            96 CRYPTSP.dll                                        C:\Windows\system32\CRYPTSP.dll                                                                                                                                                                                                                            

           284 rsaenh.dll                                         C:\Windows\system32\rsaenh.dll                                                                                                                                                                                                                             

           120 USERENV.dll                                        C:\Windows\system32\USERENV.dll                                                                                                                                                                                                                            

           104 net.dll                                            C:\eclipse\jre\bin\net.dll                                                                                                                                                                                                                                 

          1036 AcSpi64.dll                                        C:\Windows\system32\AcSpi64.dll                                                                                                                                                                                                                            

           860 OLEAUT32.dll                                       C:\Windows\system32\OLEAUT32.dll                                                                                                                                                                                                                           

            68 WTSAPI32.dll                                       C:\Windows\system32\WTSAPI32.dll                                                                                                                                                                                                                           

           452 WINHTTP.dll                                        C:\Windows\system32\WINHTTP.dll                                                                                                                                                                                                                            

           400 webio.dll                                          C:\Windows\system32\webio.dll                                                                                                                                                                                                                              

          1200 PROPSYS.dll                                        C:\Windows\system32\PROPSYS.dll                                                                                                                                                                                                                            

           340 mswsock.dll                                        C:\Windows\system32\mswsock.dll                                                                                                                                                                                                                            

            28 wship6.dll                                         C:\Windows\System32\wship6.dll                                                                                                                                                                                                                             

          1884 SETUPAPI.dll                                       C:\Windows\system32\SETUPAPI.dll                                                                                                                                                                                                                           

           216 CFGMGR32.dll                                       C:\Windows\system32\CFGMGR32.dll                                                                                                                                                                                                                           

           104 DEVOBJ.dll                                         C:\Windows\system32\DEVOBJ.dll                                                                                                                                                                                                                             

           156 IPHLPAPI.DLL                                       C:\Windows\system32\IPHLPAPI.DLL                                                                                                                                                                                                                           

            44 WINNSI.DLL                                         C:\Windows\system32\WINNSI.DLL                                                                                                                                                                                                                             

            68 dhcpcsvc6.DLL                                      C:\Windows\system32\dhcpcsvc6.DLL                                                                                                                                                                                                                          

            96 dhcpcsvc.DLL                                       C:\Windows\system32\dhcpcsvc.DLL                                                                                                                                                                                                                           

            68 nio.dll                                            C:\eclipse\jre\bin\nio.dll                                                                                                                                                                                                                                 

            84 NLAapi.dll                                         C:\Windows\system32\NLAapi.dll                                                                                                                                                                                                                             

            84 napinsp.dll                                        C:\Windows\system32\napinsp.dll                                                                                                                                                                                                                            

           100 pnrpnsp.dll                                        C:\Windows\system32\pnrpnsp.dll                                                                                                                                                                                                                            

           364 DNSAPI.dll                                         C:\Windows\system32\DNSAPI.dll                                                                                                                                                                                                                             

            44 winrnr.dll                                         C:\Windows\System32\winrnr.dll                                                                                                                                                                                                                             

           152 mdnsNSP.dll                                        C:\Program Files\Bonjour\mdnsNSP.dll                                                                                                                                                                                                                       

            28 wshtcpip.dll                                       C:\Windows\System32\wshtcpip.dll                                                                                                                                                                                                                           

            32 rasadhlp.dll                                       C:\Windows\system32\rasadhlp.dll                                                                                                                                                                                                                           

           332 fwpuclnt.dll                                       C:\Windows\System32\fwpuclnt.dll                                                                                                                                                                                                                           

           672 swt-win32-4430.dll                                 C:\eclipse\configuration\org.eclipse.osgi\869\0\.cp\swt-win32-4430.dll                                                                                                                                                                                     

           604 comdlg32.dll                                       C:\Windows\system32\comdlg32.dll                                                                                                                                                                                                                           

           452 WINSPOOL.DRV                                       C:\Windows\system32\WINSPOOL.DRV                                                                                                                                                                                                                           

          1388 WININET.dll                                        C:\Windows\system32\WININET.dll                                                                                                                                                                                                                            

            12 Normaliz.dll                                       C:\Windows\system32\Normaliz.dll                                                                                                                                                                                                                           

          2120 iertutil.dll                                       C:\Windows\system32\iertutil.dll                                                                                                                                                                                                                           

          1372 urlmon.dll                                         C:\Windows\system32\urlmon.dll                                                                                                                                                                                                                             

          1460 CRYPT32.dll                                        C:\Windows\system32\CRYPT32.dll                                                                                                                                                                                                                            

            60 MSASN1.dll                                         C:\Windows\system32\MSASN1.dll                                                                                                                                                                                                                             

            96 dwmapi.dll                                         C:\Windows\system32\dwmapi.dll                                                                                                                                                                                                                             

           612 CLBCatQ.DLL                                        C:\Windows\system32\CLBCatQ.DLL                                                                                                                                                                                                                            

            48 LINKINFO.dll                                       C:\Windows\system32\LINKINFO.dll                                                                                                                                                                                                                           

           120 swt-gdip-win32-4430.dll                            C:\eclipse\configuration\org.eclipse.osgi\869\0\.cp\swt-gdip-win32-4430.dll                                                                                                                                                                                

          2136 gdiplus.dll                                        C:\Windows\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.19061_none_2b299db671e86e03\gdiplus.dll                                                                                                                                        

          1192 WindowsCodecs.dll                                  C:\Windows\system32\WindowsCodecs.dll                                                                                                                                                                                                                      

            72 localfile_1_0_0.dll                                C:\eclipse\configuration\org.eclipse.osgi\72\0\.cp\os\win32\x86_64\localfile_1_0_0.dll                                                                                                                                                                     

            68 jWinHttp-1.0.0.dll                                 C:\eclipse\configuration\org.eclipse.osgi\75\0\.cp\jWinHttp-1.0.0.dll                                                                                                                                                                                      

           336 oleacc.dll                                         C:\Windows\system32\oleacc.dll                                                                                                                                                                                                                             

            28 msimg32.dll                                        C:\Windows\system32\msimg32.dll                                                                                                                                                                                                                            

           236 mlang.dll                                          C:\Windows\system32\mlang.dll                                                                                                                                                                                                                              

           144 sunec.dll                                          C:\eclipse\jre\bin\sunec.dll                                                                                                                                                                                                                               

            80 RpcRtRemote.dll                                    C:\Windows\system32\RpcRtRemote.dll                                                                                                                                                                                                                        

           348 apphelp.dll                                        C:\Windows\system32\apphelp.dll                                                                                                                                                                                                                            

          1832 explorerframe.dll                                  C:\Windows\system32\explorerframe.dll                                                                                                                                                                                                                      

           268 DUser.dll                                          C:\Windows\system32\DUser.dll                                                                                                                                                                                                                              

           968 DUI70.dll                                          C:\Windows\system32\DUI70.dll                                                                                                                                                                                                                              

           180 ntmarta.dll                                        C:\Windows\system32\ntmarta.dll                                                                                                                                                                                                                            

           328 WLDAP32.dll                                        C:\Windows\system32\WLDAP32.dll                                                                                                                                                                                                                            

           512 ntshrui.dll                                        C:\Windows\system32\ntshrui.dll                                                                                                                                                                                                                            

           140 srvcli.dll                                         C:\Windows\system32\srvcli.dll                                                                                                                                                                                                                             

            60 cscapi.dll                                         C:\Windows\system32\cscapi.dll                                                                                                                                                                                                                             

            44 slc.dll                                            C:\Windows\system32\slc.dll                                                                                                                                                                                                                                

            48 netutils.dll                                       C:\Windows\system32\netutils.dll                                                                                                                                                                                                                           

         10704 ieframe.dll                                        C:\Windows\System32\ieframe.dll                                                                                                                                                                                                                            

           580 SXS.DLL                                            C:\Windows\system32\SXS.DLL                                                                                                                                                                                                                                

            44 Secur32.dll                                        C:\Windows\system32\Secur32.dll                                                                                                                                                                                                                            

           148 SSPICLI.DLL                                        C:\Windows\system32\SSPICLI.DLL                                                                                                                                                                                                                            

         17492 mshtml.dll                                         C:\Windows\System32\mshtml.dll                                                                                                                                                                                                                             

            56 msimtf.dll                                         C:\Windows\system32\msimtf.dll                                                                                                                                                                                                                             

           232 msls31.dll                                         C:\Windows\system32\msls31.dll                                                                                                                                                                                                                             

           904 d2d1.dll                                           C:\Windows\system32\d2d1.dll                                                                                                                                                                                                                               

          1532 DWrite.dll                                         C:\Windows\system32\DWrite.dll                                                                                                                                                                                                                             

           668 dxgi.dll                                           C:\Windows\system32\dxgi.dll                                                                                                                                                                                                                               

           236 WINTRUST.dll                                       C:\Windows\system32\WINTRUST.dll                                                                                                                                                                                                                           

           208 d3d10_1.dll                                        C:\Windows\system32\d3d10_1.dll                                                                                                                                                                                                                            

           340 d3d10_1core.dll                                    C:\Windows\system32\d3d10_1core.dll                                                                                                                                                                                                                        

          1856 D3D10Warp.dll                                      C:\Windows\system32\D3D10Warp.dll                                                                                                                                                                                                                          

          1268 d3d10.dll                                          C:\Windows\system32\d3d10.dll                                                                                                                                                                                                                              

           300 d3d10core.dll                                      C:\Windows\system32\d3d10core.dll                                                                                                                                                                                                                          

          4016 GOOGLEPINYIN2.IME                                  C:\Windows\system32\GOOGLEPINYIN2.IME                                                                                                                                                                                                                      

          1172 dbghelp.dll                                        C:\Windows\system32\dbghelp.dll                                                                                                                                                                                                                            

           136 bcrypt.dll                                         C:\Windows\System32\bcrypt.dll                                                                                                                                                                                                                             

           304 bcryptprimitives.dll                               C:\Windows\system32\bcryptprimitives.dll                                                                                                                                                                                                                   

           152 360CloudShellExt64.dll                             C:\Program Files (x86)\360WangPan\CloudMini\360CloudShellExt64.dll                                                                                                                                                                                         

           468 QMGCShellExt64.dll                                 C:\Program Files (x86)\QQPCMgr\11.2.17063.223\QMGCShellExt64.dll                                                                                                                                                                                           

          1060 MSVCP80.dll                                        C:\Windows\WinSxS\amd64_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.6229_none_88dcc0bf2fb1b808\MSVCP80.dll                                                                                                                                               

           804 MSVCR80.dll                                        C:\Windows\WinSxS\amd64_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.6229_none_88dcc0bf2fb1b808\MSVCR80.dll                                                                                                                                               

           664 exnscan64.dll                                      C:\Program Files (x86)\QQPCMgr\11.2.17063.223\exnscan64.dll                                                                                                                                                                                                

            88 NETAPI32.dll                                       C:\Windows\system32\NETAPI32.dll                                                                                                                                                                                                                           

            84 wkscli.dll                                         C:\Windows\system32\wkscli.dll                                                                                                                                                                                                                             

           212 EhStorShell.dll                                    C:\Windows\system32\EhStorShell.dll                                                                                                                                                                                                                        

          1428 jd-eclipse.dll                                     C:\eclipse\configuration\org.eclipse.osgi\761\0\.cp\win32\x86_64\jd-eclipse.dll                                                                                                                                                                            

           652 MSVCR90.dll                                        C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.7523_none_08e1eaf5a83f8ea2\MSVCR90.dll                                                                                                                                               

     

     

    4. 参考

    通过PID获取进程路径的几种方法 安静的主页.htm

    paip. c++ 调用.net dll 最好方式powershell 使用总结. - attilax的专栏 博客频道 - CSDN.NET.htm

  • 相关阅读:
    QOS-Qos标记和QOS-Policy策略
    QOS-CBQ概述
    QOS-基本拥塞管理机制(PQ CQ WFQ RTPQ)
    QOS-QOS(服务质量)概述
    MariaDB数据库服务
    24、配置Oracle下sqlplus历史命令的回调功能
    11、nginx+tomcat+redis_session共享
    9、make和make install的区别
    10、nginx+uwsgi+django部署(动静分离)
    15、iptables_nat目标地址转换(外网访问内网)
  • 原文地址:https://www.cnblogs.com/attilax/p/15198790.html
Copyright © 2011-2022 走看看