同じプロセス名を持つ実行中のプロセス数を検出する方法を探しています。C++で実行中のプロセスの合計を計算する
例では、メモ帳を3回実行しました。
notepad.exeを notepad.exeを notepad.exeを
だから、3
を返します。私は現在実行中のプロセスを検出するために、これらのコードを持っていますが、その実行中のプロセスの数を数えていません。
#include <iostream> #include <windows.h> #include <tlhelp32.h> #include <tchar.h> bool IsProcessRunning(const char *ProcessName); int main() { char *notepadRunning = (IsProcessRunning("notepad.exe")) ? "Yes" : "No"; std::cout << "Is Notepad running? " << notepadRunning; return 0; } bool IsProcessRunning(const char *ProcessName) { PROCESSENTRY32 pe32 = { sizeof(PROCESSENTRY32) }; HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(Process32First(hSnapshot, &pe32)) { do { if(_tcsicmp(pe32.szExeFile, ProcessName) == 0) { CloseHandle(hSnapshot); return true; } } while(Process32Next(hSnapshot, &pe32)); } CloseHandle(hSnapshot); return false; }
ヘルプの任意の種類をいただければ幸いです:)
感謝を。
ありがとう:
acquirePrivilegeByNameは以下のように定義されている場合! CloseHandleを削除するだけで簡単です! –