S
S
sadacolifr2022-01-29 21:49:08
C++ / C#
sadacolifr, 2022-01-29 21:49:08

How to check if a process exists by name?

Greetings. There is a list of process names, you need to check their presence. I wrote this code, but the problem is with encodings.

bool CheckProcesses(const char* processName)
{
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

    PROCESSENTRY32 pe;
    pe.dwSize = sizeof(PROCESSENTRY32);

    if (Process32First(hSnapshot, &pe) == TRUE)
    {
        while (Process32Next(hSnapshot, &pe) == TRUE)
        {
            if (strcmp(pe.szExeFile, processName))
            {
                return true;
            }
        }
    }
    return false;
}

bool IsProcessRun() {
    const char* szExe[] = { "Sysmon64.exe", "sysmon.exe", "CFService.exe" };

    for (int i = 0; i < sizeof(szExe); i++) {
        if (CheckProcesses(szExe[i]))
            return true;
    }
    return false;
}


Is it possible to somehow change the encoding or code in order to make a normal string comparison?
Error: 'WCHAR *' is incompatible with type parameter 'const char *'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shmuel Gandin, 2022-02-03
@SollyG

This might help: https://stackoverflow.com/questions/2573834/c-conv...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question