I am currently using the EnumProcesses function to obtain a list of running processes. Since my application runs in user space, however, it is not able to get handles for processes not running under the user, including System processes. Is there another method that will give me access to these? All I need are the process names.
To open the Processes viewFrom the Spy menu, choose Processes. The figure above shows the Processes view with process and thread nodes expanded.
Windows Task Manager If your computer is running slowly, this is a beneficial tool to see a program potentially takes up too much CPU or memory resources on your computer. You can access the Task Manager by pressing the Ctrl + Alt + Del shortcut keys on your keyboard, then select Task Manager.
Retrieves the process identifier for each process object in the system.
I finally found a solution (figures after posting here as my last desperate attempt). If anyone else only needs a list of process names running on the system (all processes), this will do it for you.
Process Walking
Just to add to this answer, I built this for cases when you are looking for just one particular process instead of the entire list.
bool FindRunningProcess(AnsiString process) {
/*
Function takes in a string value for the process it is looking for like ST3Monitor.exe
then loops through all of the processes that are currently running on windows.
If the process is found it is running, therefore the function returns true.
*/
AnsiString compare;
bool procRunning = false;
HANDLE hProcessSnap;
PROCESSENTRY32 pe32;
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE) {
procRunning = false;
} else {
pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hProcessSnap, &pe32)) { // Gets first running process
if (pe32.szExeFile == process) {
procRunning = true;
} else {
// loop through all running processes looking for process
while (Process32Next(hProcessSnap, &pe32)) {
// Set to an AnsiString instead of Char[] to make compare easier
compare = pe32.szExeFile;
if (compare == process) {
// if found process is running, set to true and break from loop
procRunning = true;
break;
}
}
}
// clean the snapshot object
CloseHandle(hProcessSnap);
}
}
return procRunning;
}
I should note here this was written in Embarcadero RAD Studio (C++ Builder) and per @Remy_Lebeau System::AnsiString is a C++Builder string class for 8bit ANSI character data in its VCL/FMX frameworks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With