知识碎片之tlhelp32.h(判断进程是否开起)

The functions provided by the tool help library make it easier for you to obtain information about currently executing applications. These functions are designed to streamline the creation of tools, specifically debuggers.(工具帮助库提供的功能使您更容易获得有关当前正在执行的应用程序的信息。此库旨在简化工具的创建,特别是调试器的工具。)

#include "windows.h"
#include "tlhelp32.h"
#include "stdio.h"
DWORD GetProcessIdFromName(char * name){
	PROCESSENTRY32 pe;
	DWORD id = 0;
	HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
	pe.dwSize = sizeof(PROCESSENTRY32);
	if(!Process32First(hSnapshot,&pe)){
		return 0;
	}
	while(1){
		pe.dwSize = sizeof(PROCESSENTRY32);
		if(Process32Next(hSnapshot,&pe) == FALSE) break;
		if(strcmp(pe.szExeFile,name) == 0){
			id = pe.th32ProcessID;
			break;
		}
	}
	CloseHandle(hSnapshot);
	return id;
}
int main(){
	char name[] = "calc.exe";
	printf("%d\n",GetProcessIdFromName(name));
	return 0;
}

你可能感兴趣的:(进程,tlhelp,Windows,API, 进程判断,知识碎片)