1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <tlhelp32.h>
void PrintError(TCHAR* msg);
int main()
{
HANDLE hProcessSnap;
HANDLE hProcess;
PROCESSENTRY32 pe32;
DWORD dwPriorityClass;
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
{
PrintError(TEXT("CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS)"));
return(1);
}
pe32.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hProcessSnap, &pe32))
{
PrintError(TEXT("Process32First"));
CloseHandle(hProcessSnap);
return(1);
}
do
{
if (_tcscmp(pe32.szExeFile, TEXT("devenv.exe")) == 0)
{
_tprintf(TEXT("\n\n======================================"));
_tprintf(TEXT("\nPROCESS NAME: %s"), pe32.szExeFile);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
if (hProcess == NULL)
{
PrintError(TEXT("OpenProcess"));
}
else
{
dwPriorityClass = GetPriorityClass(hProcess);
if (!dwPriorityClass)
{
PrintError(TEXT("GetPriorityClass"));
}
CloseHandle(hProcess);
}
_tprintf(TEXT("\n Process ID = 0x%08X"), pe32.th32ProcessID);
_tprintf(TEXT("\n Parent process ID = 0x%08X"), pe32.th32ParentProcessID);
_tprintf(TEXT("\n--------------------------------------\n"));
}
} while (Process32Next(hProcessSnap, &pe32));
CloseHandle(hProcessSnap);
return 0;
}
void PrintError(TCHAR* msg)
{
DWORD errorNumber;
TCHAR sysMsg[256];
TCHAR* ptr;
errorNumber = GetLastError();
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorNumber,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
sysMsg, 256, NULL);
ptr = sysMsg;
while ((*ptr > 31) || (*ptr == 9))
++ptr;
do
{
*ptr-- = 0;
} while ((ptr >= sysMsg) && ((*ptr == '.' )|| (*ptr < 33)));
_tprintf(TEXT("\n WARNING: %s failed with error %d (%s)"), msg, errorNumber, sysMsg);
}
|