mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Process: Improve processes checking
This fixes checking for 64-bit processes on 32-bit Rainmeter and checking for elevated processes on unelevated Rainmeter.
This commit is contained in:
parent
c91f095aef
commit
e3ec9371f9
@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <Psapi.h>
|
||||
#include <TlHelp32.h>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "../../Library/RawString.h"
|
||||
@ -86,39 +86,25 @@ void CheckProcesses()
|
||||
(*iter)->isRunning = false;
|
||||
}
|
||||
|
||||
int bufSize = 256;
|
||||
DWORD* pids = new DWORD[bufSize];
|
||||
DWORD bytesReturned = 0;
|
||||
while (!EnumProcesses(pids, bufSize * sizeof(DWORD), &bytesReturned) &&
|
||||
bytesReturned == bufSize * sizeof(DWORD))
|
||||
HANDLE thSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
if (thSnapshot != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
delete [] pids;
|
||||
bufSize *= 2;
|
||||
pids = new DWORD[bufSize];
|
||||
PROCESSENTRY32 processEntry = {sizeof(processEntry)};
|
||||
if (Process32First(thSnapshot, &processEntry))
|
||||
{
|
||||
do
|
||||
{
|
||||
for (MeasureData* data : g_Measures)
|
||||
{
|
||||
if (_wcsicmp(processEntry.szExeFile, data->processName.c_str()) == 0)
|
||||
{
|
||||
data->isRunning = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (Process32Next(thSnapshot, &processEntry));
|
||||
}
|
||||
|
||||
for (UINT i = 0, isize = bytesReturned / sizeof(DWORD); i < isize; ++i)
|
||||
{
|
||||
const DWORD flags = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ;
|
||||
HANDLE hProcess = OpenProcess(flags, FALSE, pids[i]);
|
||||
if (hProcess)
|
||||
{
|
||||
WCHAR buffer[MAX_PATH];
|
||||
if (GetModuleBaseName(hProcess, NULL, buffer, _countof(buffer)))
|
||||
{
|
||||
iter = g_Measures.begin();
|
||||
for ( ; iter != g_Measures.end(); ++iter)
|
||||
{
|
||||
if (_wcsicmp(buffer, (*iter)->processName.c_str()) == 0)
|
||||
{
|
||||
(*iter)->isRunning = true;
|
||||
CloseHandle(thSnapshot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
}
|
||||
|
||||
delete [] pids;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user