当前位置: 首页>>代码示例>>C++>>正文


C++ CreateToolhelp32Snapshot函数代码示例

本文整理汇总了C++中CreateToolhelp32Snapshot函数的典型用法代码示例。如果您正苦于以下问题:C++ CreateToolhelp32Snapshot函数的具体用法?C++ CreateToolhelp32Snapshot怎么用?C++ CreateToolhelp32Snapshot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CreateToolhelp32Snapshot函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ListProcessThreads

void ListProcessThreads(DWORD dwOwnerPID)
{
    HANDLE hThreadSnap = INVALID_HANDLE_VALUE;
    THREADENTRY32 te32;

    hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);

    if (hThreadSnap == INVALID_HANDLE_VALUE)
        return;

    te32.dwSize = sizeof(THREADENTRY32);

    if (!Thread32First(hThreadSnap, &te32))
    {
        CloseHandle(hThreadSnap);
        return;
    }

    DWORD result = 0;
    do
    {
        if (te32.th32OwnerProcessID == dwOwnerPID)
        {
            printf("\n     THREAD ID = 0x%08X", te32.th32ThreadID);

            HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, te32.th32ThreadID);
            PTEB pTeb = GetTeb(hThread);
            printf("\n     TEB = %p\n", pTeb);

            CloseHandle(hThread);
        }
    } while (Thread32Next(hThreadSnap, &te32));

    printf("\n");
    CloseHandle(hThreadSnap);
}
开发者ID:ellysh,项目名称:video-game-bots,代码行数:36,代码来源:TebPebTraverse.cpp

示例2: GetProcessIDsByName

PIDList GetProcessIDsByName(const char* processName)
{
    // list of correct PIDs
    PIDList pids;

    // gets a snapshot from 32 bit processes
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hSnapshot == INVALID_HANDLE_VALUE)
    {
        printf("ERROR: Can't get snapshot from 32 bit processes, ");
        printf("ErrorCode: %u\n", GetLastError());
        return pids;
    }

    // a 32 bit process entry from a snapshot
    PROCESSENTRY32 processEntry;
    // from MSDN: The calling application must set the
    // dwSize member of PROCESSENTRY32 to the size, in bytes, of the structure.
    processEntry.dwSize = sizeof(PROCESSENTRY32);

    // checks the first process from the snapshot
    if (Process32First(hSnapshot, &processEntry))
    {
        do
        {
            // process found
            if (!strcmp(processEntry.szExeFile, lookingProcessName))
                pids.push_back(processEntry.th32ProcessID);
        }
        // loops over the snapshot
        while (Process32Next(hSnapshot, &processEntry));
    }
    CloseHandle(hSnapshot);

    return pids;
}
开发者ID:BuloZB,项目名称:SzimatSzatyor,代码行数:36,代码来源:main.cpp

示例3: ProcessList

void ProcessList()
{
	// 1. ListBox 초기화(비워주기)
	SendMessage(hMainList, LVM_DELETEALLITEMS, 0, 0);

	// 2. Process 리스트 나열  
	HANDLE	hSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0);
	if( hSnap == 0 )
		return ;

	PROCESSENTRY32 ppe;
	BOOL	b     = Process32First(hSnap, &ppe);
	while( b )
	{
		int i=0;
		// ListBox Ctrl에 데이터 추가 
		ListBoxAddData(i, ppe);

		b = Process32Next(hSnap, &ppe);
	}
	SetWindowText(hStaticLog, "프로세스 리스트를 초기화 하였습니다.");

	CloseHandle(hSnap);
}
开发者ID:gawallsibya,项目名称:BIT_API-WNP-WSP,代码行数:24,代码来源:fun.cpp

示例4: CreateToolhelp32Snapshot

bool CMDIClient::killKernel(bool bKill)
{
	bool bReturn = false;
	wchar_t p[260] = {L"moneyhub.exe"};
	this->getPriviledge();

	HANDLE hand = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
	if(hand != INVALID_HANDLE_VALUE)
	{
		PROCESSENTRY32W pew = {sizeof(PROCESSENTRY32W)};
		bool bHaveOther=false;
		Process32FirstW(hand,&pew );	

		do{
			_wcslwr_s(pew.szExeFile, 260);

			if(!wcscmp(pew.szExeFile,p) && GetCurrentProcessId()!=pew.th32ProcessID)
			{
				HANDLE h = OpenProcess(PROCESS_TERMINATE, FALSE, pew.th32ProcessID);
				if( h )
				{
					if( TerminateProcess(h, 1) )
						bReturn = true;

					CloseHandle(h);
				}
			}

		}while(Process32NextW(hand,&pew));


		CloseHandle(hand);	
	}

	return bReturn ;
}
开发者ID:Williamzuckerberg,项目名称:chtmoneyhub,代码行数:36,代码来源:MDIClient.cpp

示例5: psutil_get_name

// Return None to represent NoSuchProcess, else return NULL for
// other exception or the name as a Python string
PyObject*
psutil_get_name(long pid)
{
    HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    PROCESSENTRY32 pe = { 0 };
    pe.dwSize = sizeof(PROCESSENTRY32);

    if( Process32First(h, &pe)) {
        do {
            if (pe.th32ProcessID == pid) {
                CloseHandle(h);
                return Py_BuildValue("s", pe.szExeFile);
            }
        } while(Process32Next(h, &pe));

        // the process was never found, set NoSuchProcess exception
        NoSuchProcess();
        CloseHandle(h);
        return NULL;
    }

    CloseHandle(h);
    return PyErr_SetFromWindowsErr(0);
}
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:26,代码来源:process_info.c

示例6: FindProcess

DWORD FindProcess(TCHAR *szName) 
{ 
  HINSTANCE            hProcessSnap   = NULL; 
  PROCESSENTRY32    pe32           = {0}; 
  DWORD                dwTaskCount    = 0; 
  
  hProcessSnap = (HINSTANCE)CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | TH32CS_SNAPNOHEAPS, 0); 
  if (hProcessSnap == (HANDLE)-1) return 0; 

  dwTaskCount = 0; 
  pe32.dwSize = sizeof(PROCESSENTRY32);   // must be filled out before use 
  if (Process32First(hProcessSnap, &pe32)) { 
    do { 
      if (_wcsicmp(pe32.szExeFile,szName)==0) 
     { 
        CloseToolhelp32Snapshot(hProcessSnap); 
        return pe32.th32ProcessID; 
     } 
    } 
    while (Process32Next(hProcessSnap, &pe32)); 
  } 
  CloseToolhelp32Snapshot(hProcessSnap); 
  return 0; 
} 
开发者ID:nbclark,项目名称:flipper,代码行数:24,代码来源:FlipperSetup.cpp

示例7: GetTIDbyPID

//通过进程PID获取线程TID
DWORD GetTIDbyPID(DWORD PID)
{
	if (PID != NULL)
	{
		DWORD dwThreadID=NULL;
		THREADENTRY32 te32 = { sizeof(te32) };
		HANDLE hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
		if (Thread32First(hThreadSnap, &te32))
		{
			do
			{
				if (PID == te32.th32OwnerProcessID)
				{
					dwThreadID = te32.th32ThreadID;
					break;
				}
			} while (Thread32Next(hThreadSnap, &te32));
		}
		wprintf(L"ThreadId:%d\n", dwThreadID);
		return dwThreadID;
	}
	else
		return NULL;
}
开发者ID:BackTrackCRoot,项目名称:Auto-Inject-Dll,代码行数:25,代码来源:AutoInjectDLL.cpp

示例8: Refresh

//------------------------------------------------------
// ComboBox 에 현재의 process 목록을 저장하는 함수
//-------------------------------------------------------
void Refresh( HWND hCombo )
{
    // 1. ComboBox 초기화(비워주기)
    SendMessage(hCombo, CB_RESETCONTENT, 0, 0);

    // 2. ComboBox 채우기
    HANDLE	hSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0);

    PROCESSENTRY32 ppe;
    BOOL	b     = Process32First(hSnap, &ppe);
    while( b )
    {
        // LPARAM : 집어넣을 process명.
        int index = SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)ppe.szExeFile);

        SendMessage(hCombo, CB_SETITEMDATA, index, (LPARAM)ppe.th32ProcessID);

        b = Process32Next(hSnap, &ppe);
    }
    CloseHandle(hSnap);

    // 3. ComboBox 데이터 선택
    SendMessage(hCombo, CB_SETCURSEL, 1, 0);
}
开发者ID:gawallsibya,项目名称:BIT_API-WNP-WSP,代码行数:27,代码来源:Thread.cpp

示例9: DetectCheats

int DetectCheats(const char **names, int n, DWORD *pids)
{
	int found = 0;
	HANDLE snapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	if (snapShot == INVALID_HANDLE_VALUE)
	{
		return found;
	}

	PROCESSENTRY32 processEntry;
	processEntry.dwSize = sizeof(PROCESSENTRY32);
	ZeroMemory(&processEntry.cntUsage, sizeof(PROCESSENTRY32) - sizeof(DWORD));
	if (Process32First(snapShot, &processEntry))
	{
		do
		{
			int i;
			for (i = 0; i < n; ++i)
			{
				if (!StrICmp(GetBaseName(processEntry.szExeFile), names[i]))
				{
					continue;
				}
				else
				{
					pids[found] = processEntry.th32ProcessID;
					++found;
					DebugOutput(names[i]);
					break;
				}
			}
		} while (Process32Next(snapShot, &processEntry));
	}
	CloseHandle(snapShot);
	return found;
}
开发者ID:qwename,项目名称:quirky-protector,代码行数:36,代码来源:main.cpp

示例10: GetProcIdByProcName

unsigned long GetProcIdByProcName(const std::string& procName)
{
	PROCESSENTRY32 entry;
	DWORD dwPID = 0;

	HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	if (hSnapshot == 0 || hSnapshot == INVALID_HANDLE_VALUE)
		return dwPID;

	entry.dwSize = sizeof(entry);
	Process32First(hSnapshot, &entry);

	while (Process32Next(hSnapshot, &entry))
	{
		if (boost::iequals(entry.szExeFile, procName))
		{
			dwPID = entry.th32ProcessID;
			break;
		}
	}

	CloseHandle(hSnapshot);
	return dwPID;
}
开发者ID:evilC,项目名称:DX9-Overlay-API,代码行数:24,代码来源:Misc.cpp

示例11: CreateToolhelp32Snapshot

//Based on http://stackoverflow.com/a/1173396
void Process::kill(id_type id, bool force) {
  if(id==0)
    return;
  HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if(snapshot) {
    PROCESSENTRY32 process;
    ZeroMemory(&process, sizeof(process));
    process.dwSize = sizeof(process);
    if(Process32First(snapshot, &process)) {
      do {
        if(process.th32ParentProcessID==id) {
          HANDLE process_handle = OpenProcess(PROCESS_TERMINATE, FALSE, process.th32ProcessID);
          if(process_handle) {
            TerminateProcess(process_handle, 2);
            CloseHandle(process_handle);
          }
        }
      } while (Process32Next(snapshot, &process));
    }
    CloseHandle(snapshot);
  }
  HANDLE process_handle = OpenProcess(PROCESS_TERMINATE, FALSE, id);
  if(process_handle) TerminateProcess(process_handle, 2);
}
开发者ID:variar,项目名称:kluster,代码行数:25,代码来源:process_win.cpp

示例12: lock

//Based on http://stackoverflow.com/a/1173396
void Process::kill(bool force) {
  std::lock_guard<std::mutex> lock(close_mutex);
  if(data.id>0 && !closed) {
    HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if(snapshot) {
      PROCESSENTRY32 process;
      ZeroMemory(&process, sizeof(process));
      process.dwSize = sizeof(process);
      if(Process32First(snapshot, &process)) {
        do {
          if(process.th32ParentProcessID==data.id) {
            HANDLE process_handle = OpenProcess(PROCESS_TERMINATE, FALSE, process.th32ProcessID);
            if(process_handle) {
              TerminateProcess(process_handle, 2);
              CloseHandle(process_handle);
            }
          }
        } while (Process32Next(snapshot, &process));
      }
      CloseHandle(snapshot);
    }
    TerminateProcess(data.handle, 2);
  }
}
开发者ID:variar,项目名称:kluster,代码行数:25,代码来源:process_win.cpp

示例13: getProcList

void getProcList(){
	for (int i=0; i<32; i++)
		wsprintf(procLIST[i].szName, L"");
	PROCESSENTRY32 pe32;
	DWORD dwPID=0;
	HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPNOHEAPS | TH32CS_SNAPPROCESS, dwPID);
	if(hProcessSnap ==INVALID_HANDLE_VALUE)
		return;
	pe32.dwSize=sizeof(PROCESSENTRY32);
	if( !Process32First( hProcessSnap, &pe32 ) ){
		CloseToolhelp32Snapshot(hProcessSnap);
		return;
	}
	do{
		procLIST[iLISToffset].dwID=pe32.th32ProcessID;
		wsprintf(procLIST[iLISToffset++].szName, L"%s", pe32.szExeFile);
	} while( Process32Next( hProcessSnap, &pe32 ) );

	CloseToolhelp32Snapshot(hProcessSnap);

	//for (int i=0; i<32; i++){
	//	DEBUGMSG(1, (L"%i\t0x%08x\t'%s'\n", i, procLIST[i].dwID, procLIST[i].szName));
	//}
}
开发者ID:rodrigonh,项目名称:logging_ce,代码行数:24,代码来源:showFullScreen.cpp

示例14: kill_all

/* not really optimal, or efficient, but it's easier this way, and it's not
like we are going to be killing thousands, or even tens or processes. */
static void
kill_all(DWORD pid, HANDLE process)
{
    HANDLE process_snapshot_h = INVALID_HANDLE_VALUE;
    if ( !pid )
    {
        pid = get_process_id(process);
    }
    process_snapshot_h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    
    if (INVALID_HANDLE_VALUE != process_snapshot_h)
    {
        BOOL ok = TRUE;
        PROCESSENTRY32 pinfo;
        pinfo.dwSize = sizeof(PROCESSENTRY32);
        for (
            ok = Process32First(process_snapshot_h,&pinfo);
            TRUE == ok;
            ok = Process32Next(process_snapshot_h,&pinfo) )
        {
            if (pinfo.th32ParentProcessID == pid)
            {
                /* found a child, recurse to kill it and anything else below it */
                HANDLE ph = OpenProcess(PROCESS_ALL_ACCESS,FALSE,pinfo.th32ProcessID);
                if (NULL != ph)
                {
                    kill_all(pinfo.th32ProcessID,ph);
                    CloseHandle(ph);
                }
            }
        }
        CloseHandle(process_snapshot_h);
    }
    /* now that the children are all dead, kill the root */
    TerminateProcess(process,-2);
}
开发者ID:fullstackenviormentss,项目名称:sbmt,代码行数:38,代码来源:execnt.c

示例15: FindProcessID

DWORD FindProcessID(DWORD InheritedFromUniqueProcessId)
{


	if (InheritedFromUniqueProcessId != -1 )
	{

		HANDLE hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

		PROCESSENTRY32 pe32;

		pe32.dwSize = sizeof( PROCESSENTRY32 );

		Process32First( hSnapshot, &pe32 );
		do
		{

			if ( pe32.th32ProcessID == InheritedFromUniqueProcessId )
				break;
		}while (Process32Next( hSnapshot, &pe32 ));
		CloseHandle(hSnapshot);
	}
	return InheritedFromUniqueProcessId;
}
开发者ID:cugxiangzhenwei,项目名称:TSP_Zhenwei,代码行数:24,代码来源:TSPLoader1.cpp


注:本文中的CreateToolhelp32Snapshot函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。