I am trying to import the code from the following answer: Get full running process list ( Visual C++ )
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);
}
}
In Phil's answer, he is using System::AnsiString
class and im not sure how i can include this in my project, i.e. is it apart of the installed packages or do i need to download and include it?
An extension of this question: Is there another substitute i can use to achieve the same thing as AnsiString?
My end goal for this code is to modify it so that i can get the current list of running processes and i am looking for a specific process to terminate if it is running. I tried using a ce::string
, but since pe32.szExeFile
is type TCHAR [260]
, i am unable to pass it to a ce::string
declaration of the following ce::string process_name;
(which is probably why he is using System::AnsiString
).
I assume pe32.szExeFile
is going to return the process name, so i wanted to compare it to another declared string with the specific process name.