2
0
mirror of https://github.com/Thracky/GlosSI.git synced 2024-11-17 03:26:02 +00:00
GlosSI-fork/common/process_alive.h
Peter Repukat ce4c137a48 cleanup
note to self: sleep more
2018-03-18 17:47:26 +01:00

38 lines
920 B
C++

#pragma once
#include <Windows.h>
#include <tlhelp32.h>
namespace process_alive
{
//stolen from: https://stackoverflow.com/questions/1591342/c-how-to-determine-if-a-windows-process-is-running
inline bool IsProcessRunning(const wchar_t *processName)
{
bool exists = false;
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry))
do {
if (!_wcsicmp(entry.szExeFile, processName))
{
exists = true;
break;
}
} while (Process32Next(snapshot, &entry));
CloseHandle(snapshot);
return exists;
}
inline BOOL IsProcessRunning(DWORD pid)
{
const HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, pid);
if (process == nullptr)
return false;
const DWORD ret = WaitForSingleObject(process, 0);
CloseHandle(process);
return ret == WAIT_TIMEOUT;
}
}