/*------------------------------------
Author: Ted--Nefarian Zhu
Date: 2011/04/20 03:30
Version: V1.00 All rights reserved !
Life sucks,but we all have to move on!
------------------------------------*/
#ifndef CPROCESS_H
#define CPROCESS_H
#include <windows.h>
#include <tlhelp32.h>
class CProcess
{
public:
CProcess();
~CProcess();
BOOL New(const char* pName);
BOOL Close(const char* pName);
BOOL Check(char buff[], int size);
};
CProcess::CProcess(){}
CProcess::~CProcess(){}
BOOL CProcess::New(const char* pName)
{
HINSTANCE hInstance = ShellExecute(NULL,
"open", pName, NULL,
NULL, SW_SHOWNORMAL);
if ((int)hInstance <= 32)
{
return FALSE;
}
else return TRUE;
}
BOOL CProcess::Close(const char* pName)
{
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
HANDLE hsnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
BOOL bMore = Process32First(hsnapshot, &pe32);
while(bMore)
{
if(strcmp(pe32.szExeFile, pName) == 0)
{
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,
FALSE, pe32.th32ProcessID);
BOOL bTest = TerminateProcess(hProcess, 0);
if (bTest)
{
CloseHandle(hProcess);
CloseHandle(hsnapshot);
return TRUE;
}
else return FALSE;
}
bMore = Process32Next(hsnapshot, &pe32);
}
return FALSE;
}
BOOL CProcess::Check(char buff[],int size)
{
memset(buff, 0, size);
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
HANDLE hsnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
BOOL bMore = Process32First(hsnapshot, &pe32);
while(bMore)
{
strcat(buff, pe32.szExeFile);
strcat(buff, "\n");
bMore = Process32Next(hsnapshot, &pe32);
}
CloseHandle(hsnapshot);
return TRUE;
}
#endif /*----CPROCESS_H----*/
我寫的進程處理類---方便新建,結束,和查看進程!
最新推荐文章于 2022-10-01 10:38:29 发布