Judging from your other questions (RegSetValueEx
in the title makes it somewhat obvious), I'll presume you're on Windows. For a pure Windows API solution, you can use the Toolhelp32 API to go through a snapshot of the running processes and compare their names to the name you're looking for. You have the note about only one name, but it might be beneficial in the future, or to someone else, to have all PIDs for that name, so I'll do that:
std::vector<DWORD> pids;
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //all processes
PROCESSENTRY32W entry; //current process
entry.dwSize = sizeof entry;
if (!Process32FirstW(snap, &entry)) { //start with the first in snapshot
return 0;
}
do {
if (std::wstring(entry.szExeFile) == wantedProcessName) {
pids.emplace_back(entry.th32ProcessID); //name matches; add to list
}
} while (Process32NextW(snap, &entry)); //keep going until end of snapshot