c/c++ 如何测试(判断)某一进程是否在运行??急求!!!
2个回答
展开全部
#include "tlhelp32.h"
int GetProcessCount(const TCHAR* szExeName)
{
TCHAR sztarget[MAX_PATH];
lstrcpy(sztarget, szExeName);
CharLowerBuff(sztarget, MAX_PATH);
int count = 0;
PROCESSENTRY32 my;
HANDLE l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (((int)l) != -1)
{
my.dwSize = sizeof(my);
if (Process32First(l, &my))
{
do
{
CharLowerBuff(my.szExeFile, MAX_PATH);
if (lstrcmp(sztarget, my.szExeFile) == 0)
{
count++;
}
}while (Process32Next(l, &my));
}
CloseHandle(l);
}
return count;
}
输入进程名: szExeName
返回值: 进程运行数, 0 没运行
vc 6.0
int GetProcessCount(const TCHAR* szExeName)
{
TCHAR sztarget[MAX_PATH];
lstrcpy(sztarget, szExeName);
CharLowerBuff(sztarget, MAX_PATH);
int count = 0;
PROCESSENTRY32 my;
HANDLE l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (((int)l) != -1)
{
my.dwSize = sizeof(my);
if (Process32First(l, &my))
{
do
{
CharLowerBuff(my.szExeFile, MAX_PATH);
if (lstrcmp(sztarget, my.szExeFile) == 0)
{
count++;
}
}while (Process32Next(l, &my));
}
CloseHandle(l);
}
return count;
}
输入进程名: szExeName
返回值: 进程运行数, 0 没运行
vc 6.0
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询