效果如下:
#include "stdafx.h" #include#include #include #include BOOL judge = FALSE; DWORD GetProcessID(char *ProcessName){ PROCESSENTRY32 pe32; pe32.dwSize = sizeof(pe32); HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hProcessSnap == INVALID_HANDLE_VALUE){ printf("CreateToolhelp32Snapshot errorn"); return 0; } BOOL bProcess = Process32First(hProcessSnap, &pe32); while (bProcess){ char* str1 = pe32.szExeFile; char* str2 = ProcessName; // 创建一个字符串数组 char arr1[255] = { 0 }; // 利用字符串拷贝函数进行拷贝 strcpy(arr1, str1); // 例如内存拷贝函数进行拷贝 memcpy(arr1, str1, sizeof(arr1)); // 创建一个字符串数组 char arr2[255] = { 0 }; // 利用字符串拷贝函数进行拷贝 strcpy(arr2, str2); // 例如内存拷贝函数进行拷贝 memcpy(arr2, str2, sizeof(arr2)); if (strcmp(strupr(arr1), strupr(arr2)) == 0){ judge = true; } bProcess = Process32Next(hProcessSnap, &pe32); } CloseHandle(hProcessSnap); return 0; } int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. GetProcessID("chrome.exe"); if (judge == TRUE){ MessageBox(NULL, "find chrome.exe ","Test",0); }else{ MessageBox(NULL, "not find chrome.exe", "Test", 0); } return 0; }



