Here is a complete solution. The function will be called as
SetProcessProirity(L"excel.exe",BELOW_NORMAL_PRIORITY_CLASS)
Here is the function I created:
void SetProcessProirity(LPWSTR ProcessName, int Priority)
{
PROCESSENTRY32 proc32;
HANDLE hSnap;
if (hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0));
if (hSnap == INVALID_HANDLE_VALUE)
{
}
else
{
proc32.dwSize = sizeof(PROCESSENTRY32);
while ((Process32Next(hSnap, &proc32)) == TRUE)
{
if (_wcsicmp(proc32.szExeFile, ProcessName) == 0)
{
HANDLE h = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_SET_INFORMATION ,TRUE, proc32.th32ProcessID);
SetPriorityClass(h, BELOW_NORMAL_PRIORITY_CLASS);
CloseHandle(h);
}
}
CloseHandle(hSnap);
}
}