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:[email protected]

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

时间: 01-15

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

delphi根据进程PID获取程序所在路径的函数(用OpenProcess取得句柄,用GetModuleFileNameEx取得程序名)

uses psapi; {根据进程PID获取程序所在路径的函数}function GetProcessExePath(PID: Cardinal): string;varpHandle: THandle;buf: array[0..MAX_PATH] of Char;begin{获取进程句柄}pHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);{获取进程路径}GetModuleFileN

如何获取启动文件路径 GetModuleFileName

如何获取启动文件路径 GetModuleFileName CString GetExeDirPath() { char fn[MAX_PATH] = {0}; CString strExeDirPath; GetModuleFileName(NULL, strExeDirPath.GetBufferSetLength(MAX_PATH), MAX_PATH);//获取启动路径:"c:\Users\whl\Desktop\Example\Debug\Example.exe" CStrin

Atitit.收银机小票打印功能的设计  java php c#.net版本

Atitit.收银机小票打印功能的设计  java php c#.net版本 1. 1. 打印方式有4种:1 1.1. 1.1. 一是不经过任何修改,直接调用javascript中的window.print()打印.1 1.2. 1.2. 二根据客户要求的报表格式,编写相应格式的html,装载数据打印,同样调用window.print()打印,只是对html的格式要求比较高.1 1.3. 1.3. 三是通过客户提供的word格式,通过xml配置文件与数据库的数据进行关联,自动装载数据到word中

【转】[内核/驱动]驱动中获取进程全路径和注册表全路径

转载地址: http://blog.sina.com.cn/s/blog_60a1a51d0100e78g.html 2008.07.05 经过这几天的努力,注册表保护驱动已经基本稳定.很多人都在网上问如何获取访问注册表的进程全路径和被访问的注册表的全路径,下面就将部分代码贴出来. //驱动中获取被访问注册表的全路径 BOOLEAN GetRegFullPath(HANDLE KeyHandle, PUNICODE_STRING pRegFullPath) { POBJECT pKey = NU

::GetModuleFileName 获取DLL文件路径

通过GetModuleHandle(NULL, .., .. ); 只能获取到 EXE文件所在路径,如果需要获取DLL路径怎么办? 有如下两种办法: 1. 从DllMain(hModule, …)中获取DLL句柄,并传入GetModuleHandle(); 但有些DLL被封装过的很难找到hModule,如: MFC的DLL, vstest的UnitTest DLL 等. 2.  变量 IMAGE_DOS_HEADER __ImageBase 可以转换为 hModule,传入GetModuleHa

Android之——获取进程总数、内存、任务列表

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47263863 如今,基于Android平台的应用越来越多,不乏这样一些应用程序,这些应用可以多手机中的进程,内存和任务列表进行管理.Android系统中没有自带的应用程序对这些数据进行管理.大家不禁会说,Android的应用设置里面有这些功能啊!是的,虽然应用设置里面有,但是我们如果想看一下系统的进程,还要跑到系统设置里面去看吗?这样是不是很麻烦?是不是很挫呢?那获取Androi

Excel公式 提取文件路径后缀

我们在代码中获取一个文件路径的后缀,是一个很简单的事. 如C#中,可以通过new FileInfo(filePath).Extension,或者Path.GetExtension(filePath)获取. 而Excel的大数据中,直接批量获取同行单元格内容中文件路径的后缀,该如何获取? 如上,想获取文件后缀,然后从中分析出文件的所属开发语言. 公式如下: 1.获取后缀 =RIGHT(D2,LEN(D2)-FIND("@",SUBSTITUTE(D2,".",&quo

Atitit.获取approot api 应用根路径 java c#.net php asp

Atitit.获取approot api 应用根路径 java c#.net php asp 1. 如果根路径返回empty,否则返回/app,兼容getContextPath() <script type="text/javascript" src="../com.attilax/core/approot_js.jsp"></script> <%@ page contentType="text/html; charset=u

java项目获取文件路径总结

版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] java获取文件路径的方式比较多,总结可能有疏漏. 1.java.lang.System.getProperty(String key) System.getProperty("user.dir")这个方法的作用可以获取当前工程的根目录. ![我的一个项目](http://img.blog.csdn.net/20160322141415562) 比如获取上图中项目的根目录:C:\Users\Administrato