Chinaunix首页 | 论坛 | 博客
  • 博客访问: 74506
  • 博文数量: 29
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 337
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-24 20:02
文章分类

全部博文(29)

文章存档

2011年(1)

2009年(1)

2008年(27)

我的朋友

分类:

2008-12-07 18:57:47

#include
#include
int getpid(char *name)
{
    HANDLE          hprocessSnap = NULL;
    PROCESSENTRY32 pe32          ={0};
    hprocessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    if (hprocessSnap ==(HANDLE)-1) {  
       printf("\nCreateToolhelp32Snapshot()failed:%d",GetLastError());
       return 1;
    }
    pe32.dwSize = sizeof(PROCESSENTRY32);
    if (Process32First(hprocessSnap,&pe32)){
       do {
          printf("\n%-20s%d",pe32.szExeFile,pe32.th32ProcessID);
          if (!strcmp(name, pe32.szExeFile))
          return (int)pe32.th32ProcessID;
      }while (Process32Next(hprocessSnap,&pe32));
    }
    else
         printf("\nProcess32Firstt() failed:%d",GetLastError());
    CloseHandle (hprocessSnap);
    return 0;
}
阅读(532) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~