通过进程ID获取进程名
2016-03-06 20:38
274 查看
通过进程ID获取进程名
网上流传代码:
自我改编代码
D7编译通过!
网上流传代码:
uses TLhelp32 function GetProcessNameById(const AID: Integer): String; var h:thandle; f:boolean; lppe:tprocessentry32; begin Result := ''; h := CreateToolhelp32Snapshot(TH32cs_SnapProcess, 0); lppe.dwSize := sizeof(lppe); f := Process32First(h, lppe); while integer(f) <> 0 do begin if Integer(lppe.th32ProcessID) = AID then begin Result:= StrPas(lppe.szExeFile); break; end; f := Process32Next(h, lppe); end; end.
自我改编代码
uses TLhelp32,PsAPI; function GetProcessName(ProcessID: DWORD): string; var Hand: THandle; ModName: array[0..Max_Path - 1] of Char; hMod: HModule; n: DWORD; begin Result := ''; Hand := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, ProcessID); if Hand > 0 then try try ENumProcessModules(Hand, @hMod, Sizeof(hMod), n); if GetModuleFileNameEx(Hand, hMod, ModName, Sizeof(ModName)) > 0 then Result := ExtractFileName(ModName); except end; finally CloseHandle(Hand); end; end; end.
D7编译通过!
相关文章推荐
- 1201 18岁生日
- 【VS开发】recv函数函数返回值说明(特别有利于工程调试)
- NYOJ 题目860 又见01背包 (特别版01背包)
- 1045. 快速排序(25)
- (java) Kth Smallest Element in a BST
- vector容器的三种遍历方法
- 【java学习记录】spilt小结
- Linux内核分析二:一个简单的时间片轮转多道程序内核代码
- 自我介绍
- yii框架-依赖注入
- 背包
- HDU 3873 Invade the Mars dijkstra最短路
- 整理:统计学习-2 感知机知识准备(模型类型、超平面与梯度下降法)
- 对类依据成员进行排序
- 八个排序算法
- 谋哥:App排行榜的秘密
- const
- 骨骼算法,仿生中的外观
- Java [Leetcode 268]Missing Number
- 个人项目-数组求和(语言:C++)