|
纯C语言写的(个人不喜欢C++),Code::Blocks编译。
- #include <stdio.h>
- #include <conio.h>
- #include <windows.h>
- #include <tlhelp32.h>
- long TaGetPidByPIN(char *ProcessImageName)
- {
- PROCESSENTRY32 procxp= {0};
- HANDLE hsnapshot1=NULL;
- BOOL flags=1;
- int i=0;
- hsnapshot1=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
- procxp.dwSize=sizeof(procxp);
- flags=Process32First(hsnapshot1,&procxp);
- if(!flags) return 0;
- while(flags)
- {
- if(stricmp(ProcessImageName,procxp.szExeFile)==0)
- return procxp.th32ProcessID;
- i++;
- flags=Process32Next(hsnapshot1,&procxp);
- }
- CloseHandle(hsnapshot1);
- return 0;
- }
- int main()
- {
- printf("%ld\n",TaGetPidByPIN("TASKmgr.ExE"));
- printf("%ld\n",TaGetPidByPIN("svcHOST.ExE"));
- return 0;
- }
复制代码
|
|