通过进程名获得进程ID
2011-11-12 15:28
483 查看
View Code
#include<windows.h> #include<iostream> #include<tlhelp32.h> #include<TCHAR.h> using namespace std; HANDLE GetProcessHandle(int nID)//通过进程ID获取进程句柄 { return OpenProcess(PROCESS_ALL_ACCESS, FALSE, nID); } HANDLE GetProcessHandle(LPCTSTR pName)//通过进程名获取进程句柄 { HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (INVALID_HANDLE_VALUE == hSnapshot) { return NULL; } PROCESSENTRY32 pe = { sizeof(pe) }; BOOL fOk; for (fOk = Process32First(hSnapshot, &pe); fOk; fOk = Process32Next(hSnapshot, &pe)) { if (!_tcscmp(pe.szExeFile, pName)) { CloseHandle(hSnapshot); return GetProcessHandle(pe.th32ProcessID); } } return NULL; } int main() { HANDLE h=GetProcessHandle("taskmgr.exe"); if(h==NULL) { printf("no"); } else { printf("yes"); } return 0; }
相关文章推荐
- 通过进程ID获得该进程主窗口的句柄
- 在linux中通过进程名获得进程id
- 在linux中通过进程名获得进程id
- 通过进程号ID获得窗口的句柄
- 通过进程ID获得该进程主窗口的句柄
- 通过进程ID获得主窗口句柄
- 通过进程ID获得该进程主窗口的句柄
- 9x下通过执行文件名获得进程ID的方法
- 通过进程ID或进程名,获得创建进程的信息(PerformanceCounter)
- 通过进程ID获得该进程主窗口的句柄或者获得特定窗口句柄
- 通过进程号ID获得窗口的句柄
- 通过进程ID获得主窗口句柄
- windows驱动里通过进程ID获得进程名和所属用户
- 通过进程ID获得该进程主窗口的句柄
- 在linux中通过进程名获得进程id
- 通过进程号ID获得窗口的句柄 .
- Magento通过可配置(configurable)商品Id获得子类Ids
- vc通过进程名返回进程id
- Linux下启动Java进程并获得进程ID(PID)
- 通过创建窗口进程的ID来查找窗口句柄