void ProcessList::init() { HANDLE h; PROCESSENTRY32 pe32; h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (h == INVALID_HANDLE_VALUE) { return; } pe32.dwSize = sizeof(PROCESSENTRY32); if (!Process32First(h, &pe32)) { return; } do { HANDLE hProcess = getProcessHandle(pe32.th32ProcessID); if (!hProcess) { continue; } QString name = getProcessName(pe32.th32ProcessID); #ifndef _WIN32_WCE PSID sid = getProcessOwner(hProcess); if (!sid || m_userId && !EqualSid(m_userId, sid)) { freeSid(sid); continue; } #else PSID sid = 0; #endif m_processes << new ProcessListEntry(hProcess, name, pe32.th32ProcessID, sid); } while (Process32Next(h, &pe32)); #ifndef _WIN32_WCE CloseHandle(h); #else CloseToolhelp32Snapshot(h); #endif }
BOOL FindProcess (const char* needle, char* buf, size_t bufsize) { HANDLE h = getProcessHandle(needle, buf, bufsize); if (h) CloseHandle(h); return !!h; }