I am developing an application, which will monitor some applications. In the startup of the application, it will check if the listed application is running or not. If not running it will create a new process for those applications.
I can identify the processes running using the below code:
HANDLE hSnapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE)
return Error("Failed to create snapshot");
PROCESSENTRY32 pe;
pe.dwSize = sizeof(pe);
if (!::Process32First(hSnapshot, &pe))
return Error("Failed in Process32First");
do {
printf("PID:%6d (PPID:%6d): %ws (Threads=%d) (Priority=%d)\n",
pe.th32ProcessID, pe.th32ParentProcessID, pe.szExeFile, pe.cntThreads, pe.pcPriClassBase);
} while (::Process32Next(hSnapshot, &pe));
::CloseHandle(hSnapshot);
I can get the executable of the processes from here. But I want to check the command line info too. for example, I need to distinguish between python hello.py and python run.py. Without the command line arguments, I can't be sure whether the desired process is running or not.
How can I get the command-line arguments of other processes? Or, is there any other way I can determine if my desired process is running?