GetProcessIdByName - Get first pid given a process name. You should probably use GetProcessIdsByName instead. returns a DWORD pid if procName is a running process, otherwise returns 0 */
| 267 | returns a DWORD pid if procName is a running process, otherwise returns 0 |
| 268 | */ |
| 269 | DWORD Process::GetProcessIdByName(__in const wstring procName) |
| 270 | { |
| 271 | PROCESSENTRY32 entry; |
| 272 | entry.dwSize = sizeof(PROCESSENTRY32); |
| 273 | DWORD pid = 0; |
| 274 | |
| 275 | HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); |
| 276 | |
| 277 | if (Process32First(snapshot, &entry) == TRUE) |
| 278 | { |
| 279 | while (Process32Next(snapshot, &entry) == TRUE) |
| 280 | if (wcscmp(entry.szExeFile, procName.c_str()) == 0) |
| 281 | { |
| 282 | pid = entry.th32ProcessID; |
| 283 | break; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | CloseHandle(snapshot); |
| 288 | return pid; |
| 289 | } |
| 290 | |
| 291 | |
| 292 | /* |
nothing calls this directly
no outgoing calls
no test coverage detected