How to get Process ID of running application?

  • Thread starter Thread starter StudiousStudent
  • Start date Start date
S

StudiousStudent

Guest
I'm trying toi get the process ID of a running application. But I think I may be doing it wrong. Any help would be appreciated.

HANDLE hProcessSnap;
HANDLE hProcess;
PROCESSENTRY32 pe32;
bool processFound = 0;
TCHAR fileName[] = TEXT("FileAshAndBen.exe");

// ------------ Getting List of Running Processes ------------//

hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if (hProcessSnap == INVALID_HANDLE_VALUE)
{
cout << "CreateToolhelp32Snapshot (of process) is failed\n";
return 0;
}

// ---------------- Getting FIle Process ID ----------------//

// Set the size of the pe32 structure before using it
pe32.dwSize = sizeof(PROCESSENTRY32);

if (!Process32First(hProcessSnap, &pe32));
{
cout << "Process32First failed \n";
// clean the snapshot object
CloseHandle(hProcessSnap);
}

// Go through all the processes looking for FileAshAndBen.exe
do
{
// print out the process name
wcout << "\nProcess name is " << pe32.szExeFile << endl;

// if the process name is FileAshAndBen.exe
if (_tcscmp(pe32.szExeFile, fileName) == 0)
{
cout << "File process is found \n";
processFound = 1;
break;
}
} while (Process32Next(hProcessSnap, &pe32));





StudiousStudent

Continue reading...
 
Back
Top