本文整理匯總了C++中EnumProcesses函數的典型用法代碼示例。如果您正苦於以下問題:C++ EnumProcesses函數的具體用法?C++ EnumProcesses怎麽用?C++ EnumProcesses使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了EnumProcesses函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: get_processes
// Returns the process ID for each process object in the system.
inline std::vector<DWORD> get_processes()
{
std::vector<DWORD> ids(512);
const DWORD bytes = static_cast<DWORD>(ids.size()) * sizeof(DWORD);
DWORD bytes_returned = 0;
BOOL res = EnumProcesses(&ids[0], bytes, &bytes_returned);
if (!res)
{
std::cerr << "could not retrieve process identifiers: "
<< system_error_string() << std::endl;
}
DWORD actual_proc_count = bytes_returned / sizeof(DWORD);
while (actual_proc_count == ids.size())
{
std::clog << "retry (process count: " << actual_proc_count
<< ")" << std::endl;
ids.resize(10 * actual_proc_count);
EnumProcesses(&ids[0],
static_cast<DWORD>(ids.size()) * sizeof(DWORD),
&bytes_returned);
actual_proc_count = bytes_returned / sizeof(DWORD);
}
auto it = ids.begin();
std::advance(it, actual_proc_count);
ids.erase(it, ids.end());
return ids;
}
示例2: sizeof
EnumProcessesResponse *getAllPids() {
DWORD size = sizeof(DWORD) * 512;
DWORD *aProcesses = NULL;
DWORD cbNeeded, cProcesses;
EnumProcessesResponse *res = calloc(1, sizeof(*res));
// EnumProcesses modifies cbNeeded, setting it to the amount of bytes
// written into aProcesses. Thus, we need to check if cbNeeded is equal
// to size. In that case, it means that the array was filled completely and
// we need to use a bigger array because probably we left elements out.
do {
size *= 2;
aProcesses = realloc(aProcesses, size);
BOOL success = EnumProcesses(aProcesses, size, &cbNeeded);
if (!success) {
res->error = GetLastError();
free(aProcesses);
return res;
}
}
while(cbNeeded == size);
res->error = 0;
res->pids = aProcesses;
res->length = cbNeeded/sizeof(DWORD);
return res;
}
示例3: kill_process
void kill_process(string name)
{
#ifdef _WIN32
CHAR szProcBuff[101];
DWORD pIDs[300], dwBytesReturned;
HANDLE hProcess;
INT i, procCount;
EnumProcesses(pIDs, sizeof(pIDs), &dwBytesReturned);
procCount = dwBytesReturned / sizeof(DWORD);
for (i = 0; i < procCount; i++)
if (pIDs[i] != 0)
{
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_TERMINATE, 0, pIDs[i]);
GetModuleBaseName(hProcess, 0, szProcBuff, 100);
if (strcmp(szProcBuff, name.c_str()) == 0)
TerminateProcess(hProcess, EXIT_SUCCESS);
CloseHandle(hProcess);
}
#elif __APPLE__
string command = "killall -kill " + name;
system(command.c_str());
#endif
while (process_running(name.c_str()) > 0)
Sleep(1);
}
示例4: getProcessID
int getProcessID(const char * name)
{
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
memset(&aProcesses, 0, sizeof(aProcesses));
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
{
return 0;
}
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Print the name and process identifier for each process.
for ( i = 0; i < cProcesses; i++ )
{
if( aProcesses[i] != 0 )
{
if (isThisProcessID( aProcesses[i], name ))
return aProcesses[i];
}
}
return 0;
}
示例5: numberOfAkbashProcesses
int numberOfAkbashProcesses(char * name)
{
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
int akbashCount = 0;
memset(&aProcesses, 0, sizeof(aProcesses));
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
{
return 0;
}
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Print the name and process identifier for each process.
for ( i = 0; i < cProcesses; i++ )
{
if( aProcesses[i] != 0 )
{
if (isThisProcessID( aProcesses[i], name))
{
akbashCount++;
}
}
}
return akbashCount;
}
示例6: GetProcessId
int GetProcessId(const char* file_name)
{
const int maximum_processes = 1024;
LPDWORD process_ids;
LPTSTR base_name;
HANDLE process;
DWORD i, processes, process_id = 0;
process_ids = (LPDWORD)HeapAlloc(GetProcessHeap(), 0, maximum_processes * sizeof(DWORD));
if(process_ids != NULL) {
if(EnumProcesses(process_ids, maximum_processes * sizeof(DWORD), &processes)) {
base_name = (LPTSTR)HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(TCHAR));
if(base_name != NULL) {
processes = processes / sizeof(DWORD);
for(i = 0; i < processes; i++) {
process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, process_ids[i]);
if(process != NULL) {
if(GetModuleBaseName(process, NULL, base_name, MAX_PATH) > 0) {
if(!lstrcmpi(base_name, file_name)) {
process_id = process_ids[i];
CloseHandle(process);
break;
}
}
CloseHandle(process);
}
}
HeapFree(GetProcessHeap(), 0, (LPVOID)base_name);
}
}
HeapFree(GetProcessHeap(), 0, (LPVOID)process_ids);
}
return process_id;
}
示例7: startDaemonScan
void startDaemonScan()
{
PVOID buffer = VirtualAlloc(NULL, 1024 * 1024, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
while (1)
{
DWORD procIDsBuffer[MAX_PROCESSES];
DWORD size_returned;
EnumProcesses(procIDsBuffer, sizeof(procIDsBuffer), &size_returned);
int numProc = size_returned / sizeof(DWORD);
int i;
TCHAR strBuffer[MAX_PATH];
for (i = 0; i < numProc; i++)
{
DWORD curr_pid = (int)procIDsBuffer[i];
HANDLE Handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, TRUE, curr_pid);
GetModuleBaseName(Handle, NULL, strBuffer, MAX_PATH);
if ((Handle) && isInFrobProcList(strBuffer))
reactToProcess(curr_pid, strBuffer);
CloseHandle(Handle);
}
updateList();
}
}
示例8: ensure_not_running
static BOOL ensure_not_running(LPCWSTR dest) {
DWORD processes[4096], needed, num;
unsigned int i;
WCHAR name[4*MAX_PATH] = L"<unknown>";
HANDLE h;
DWORD len;
LPWSTR fname = NULL;
if ( !EnumProcesses( processes, sizeof(processes), &needed ) ) {
return true;
}
num = needed / sizeof(DWORD);
for (i = 0; i < num; i++) {
if (processes[i] == 0) continue;
h = OpenProcess( PROCESS_QUERY_INFORMATION, FALSE, processes[i] );
if (h != NULL) {
len = GetProcessImageFileNameW(h, name, 4*MAX_PATH);
CloseHandle(h);
if (len != 0) {
name[len] = 0;
fname = PathFindFileName(name);
if (wcscmp(fname, L"calibre.exe") == 0) {
show_error(L"Calibre appears to be running on your computer. Please quit it before trying to install Calibre Portable.");
return false;
}
}
}
}
return true;
}
示例9: main
int main()
{
DWORD ProcessCount;
DWORD cbNeeded;
DWORD ProcessId[1024];
EnumProcesses(ProcessId,sizeof(ProcessId),&cbNeeded);
ProcessCount = cbNeeded/sizeof(DWORD);
HMODULE hModule;
char szPath[MAX_PATH];
for(DWORD i = 0; i < ProcessCount; i ++)
{
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,FALSE,ProcessId[i]);
if(hProcess)
{
EnumProcessModules(hProcess,&hModule,sizeof(hModule),&cbNeeded);
GetModuleFileNameEx(hProcess,hModule,szPath,sizeof(szPath));
printf("PID:%d \t%s\n",ProcessId[i],szPath);
}
else
continue;
}
return 0;
}
示例10: DetectChrome
bool DetectChrome(ChromeInfo* pPrevInfo, const TCHAR* tcChromeImageName, bool bRetry = false) {
if(pPrevInfo && pPrevInfo->bValid) {
pPrevInfo->bValid = MatcProcessImageName(pPrevInfo->dwProcId, tcChromeImageName, true);
if(!(!pPrevInfo->bValid && bRetry))
return pPrevInfo->bValid;
}
DWORD runningProcessIds[1024], dwRetCount;
int nProcCount;
if(!EnumProcesses( runningProcessIds, sizeof(runningProcessIds), &dwRetCount )) return false;
nProcCount = dwRetCount/sizeof(DWORD);
for (int i = nProcCount; i > 0; --i ) {
DWORD dwCurrentProcId = runningProcessIds[i];
if(0 != dwCurrentProcId) {
if(MatcProcessImageName(dwCurrentProcId, tcChromeImageName)){
DWORD dwChromePid = dwCurrentProcId;
DWORD dwParent = GetProcessParentPid(dwChromePid);
if(NULL != dwParent && MatcProcessImageName(dwParent, tcChromeImageName, true)){
dwChromePid = dwParent;
}
if (pPrevInfo) {
pPrevInfo->bValid = true;
pPrevInfo->dwProcId = dwChromePid;
}
return true;
}
}
}
return false;
}
示例11: proc_run_func
/* FIXME */
g_val_t
proc_run_func( void )
{
DWORD aProcesses[MAXPROCESSES], cbNeeded, cProcesses;
unsigned int i, running = 0;
HANDLE hProcess;
BOOL bResult;
g_val_t val;
if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded)) {
cProcesses = 0;
} else {
cProcesses = cbNeeded / sizeof(DWORD);
}
#if (_WIN32_WINNT >= 0x0501)
/* Only for XP or newer */
for (i = 0; i < cProcesses; i++)
if (aProcesses[i] != 0) {
hProcess = OpenProcess (PROCESS_QUERY_INFORMATION,
FALSE, aProcesses[i]);
if (hProcess != NULL) {
if (IsProcessInJob(hProcess, NULL, &bResult)) {
if (bResult)
running++;
}
CloseHandle(hProcess);
}
}
#endif
val.uint32 = running;
return val;
}
示例12: GetProcessID
ULONG GetProcessID(LPCSTR TargetProcessName)
{
DWORD nSize = MAX_PATH;
HANDLE hCurrentProcess;
CHAR BaseName[MAX_PATH];
DWORD aProcesses[1024], cbNeeded;
unsigned int i;
if (!EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded))
return FALSE;
// NumberProcesses = nSize = cbNeeded / sizeof(DWORD);
for (i = 0; i <= nSize; i++)
{
if(NULL != (hCurrentProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, aProcesses[i])))
{
GetModuleBaseName(hCurrentProcess, NULL, BaseName, sizeof(BaseName));
if(0 == stricmp(BaseName, TargetProcessName))
{
CloseHandle(hCurrentProcess);
return aProcesses[i];
}
}
CloseHandle(hCurrentProcess);
}
return FALSE;
}
示例13: test_exist_process
// Determine le nombre de processus du nom de "monProcess" en cours d'éxécution
int test_exist_process(const char* monProcess)
{
int nombreTrouves = 0;
DWORD processes[MAX_TAB], nb_processes;
char process_name[MAX_TAB];
int i;
HANDLE hprocess;
EnumProcesses(processes, sizeof(processes), &nb_processes);
//On teste tous les processus pour voir si leur nom correspond
for(i = 0 ; i < nb_processes / sizeof(DWORD) ; i++)
{
hprocess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processes[i]);
//Prend le nom du processus et le met dans process_name
GetModuleBaseName(hprocess, NULL, process_name, sizeof(process_name));
CloseHandle(hprocess);
if(strcmp(process_name, monProcess) == 0)
{
nombreTrouves++;
}
}
return nombreTrouves;
}
示例14: Thread_1
//Open a thread to get the processID and control the process
DWORD WINAPI Thread_1 (LPVOID lpParam)
{
DWORD pProcessIds[1024],cbReturned,cProcesses;
DWORD pProcessIdWanted = 0;
TCHAR sProcessName[MAX_PATH] = TEXT("minesweeper.exe");
unsigned int i;
if(!EnumProcesses(pProcessIds,sizeof(pProcessIds),&cbReturned))
{
return 1;
}
//Number of Processes returned from Enum from Byte to #
cProcesses = cbReturned / sizeof(DWORD);
for(i=0;i<cProcesses;i++)
{
if(pProcessIds[i] != 0)
{
pProcessIdWanted = GetProcessIdByName(pProcessIds[i], sProcessName);
if(pProcessIdWanted != 0) break;
}
}
pProcessIdWanted ? cout<< pProcessIdWanted <<endl : cout<<"Process Not Found" << endl;
GetProcessBaseAddr(pProcessIdWanted);
return 0;
}
示例15: EnumProc
int Monitor::EnumProc(DWORD *pArr)
{
DWORD i = 0;
if (!EnumProcesses(pArr, sizeof(pArr), &i))
return -1;
return i / sizeof(DWORD);
}