• Blog
  • Local Log
  • Tag Cloud
  • Key Log
  • Guestbook
  • RSS Feed
  • Write a Post
  • Admin

혹시 블로그 스킨이 깨져 보이시나요? 최신버전의 Internet Explorer(Windows용), Opera, Firefox를 사용해보세요.

Enumerating All Processes

Win32 API/MFC
2008/08/06 16:14
 

Enumerating All Processes

Task Manager is an example of a program that enumerates all running processes. It is implemented using data from the performance registry. The following sample code uses the EnumProcesses function to enumerate the current processes in the system. This method is easier than using the performance registry.

#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "psapi.h"

void PrintProcessNameAndID( DWORD processID )
{
    TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");

    // Get a handle to the process.

    HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
                                   PROCESS_VM_READ,
                                   FALSE, processID );

    // Get the process name.

    if (NULL != hProcess )
    {
        HMODULE hMod;
        DWORD cbNeeded;

        if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), 
             &cbNeeded) )
        {
            GetModuleBaseName( hProcess, hMod, szProcessName, 
                               sizeof(szProcessName)/sizeof(TCHAR) );
        }
    }

    // Print the process name and identifier.

    _tprintf( TEXT("%s  (PID: %u)\n"), szProcessName, processID );

    CloseHandle( hProcess );
}

void main( )
{
    // Get the list of process identifiers.

    DWORD aProcesses[1024], cbNeeded, cProcesses;
    unsigned int i;

    if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
        return;

    // 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 )
            PrintProcessNameAndID( aProcesses[i] );
}

The main function obtains a list of processes by using the EnumProcesses function. For each process, main calls the PrintProcessNameAndID function, passing it the process identifier. PrintProcessNameAndID in turn calls the OpenProcess function to obtain the process handle. If OpenProcess fails, the output shows the process name as <unknown>. For example, OpenProcess fails for the Idle and CSRSS processes because their access restrictions prevent user-level code from opening them. Next, PrintProcessNameAndID calls the EnumProcessModules function to obtain the module handles. Finally, PrintProcessNameAndID calls the GetModuleBaseName function to obtain the name of the executable file and displays the name along with the process identifier.

크리에이티브 커먼즈 라이센스
Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
TAG Enumerating All Processes, Process Name, ProcessName
No received trackback. / No comment.

Trackback Address :: http://sinwoong.co.kr/trackback/260

You can also say.

Prev 1 ... 32 33 34 35 36 37 38 39 40 ... 285 Next
달빛는 지금.. 파이팅파이팅
C와 Assembly를 제2외국어로...
남자RH+ O형사수자리경기도

카테고리

  • 전체 (285)
    • Project HSL (2)
    • Project Talk (8)
    • 생각 (16)
    • 일상 (18)
    • 정보/스크랩 (64)
    • 용어사전 (4)
    • IT외부행사 (15)
    • ASSEMBLY (7)
    • Win32 API/MFC (29)
    • Hacking/Virus/Vaccine (24)
    • 관심거리 (3)
    • 스킨/플러그인 (2)
    • 시간 죽이기 (2)
    • 천연 비누/화장품 (10)
    • Windows Server 2008 (57)
    • 디바이스 드라이버 (23)
    • 카드 (1)
    • 지식베이스캠프 (0)
    • 소프트캠프 업무 일지 (0)

태그목록

  • 웰빙
  • 실행파일 구조
  • 온라인 예절
  • PCI
  • Window I/O
  • 정보통신망법
  • 유언장
  • 지하철
  • 홈페이지
  • DragAcceptFiles
  • EnumPrinters
  • 노선도
  • 문서폐기 보안
  • 건강
  • Multibyte
  • 불법 소프트웨어 이용
  • 보안회사
  • 플러그인
  • DragFinish
  • Bottled Music
  • 죽음
  • 카드
  • 인식
  • 조기교육
  • 블랙해커
  • 걷기
  • 사후
  • 현대자동차
  • Detoured.dll
  • Enumerating All Processes

최근에 올라온 글

  • ExitProcess(), Termina....
  • C/C++ 격리된 응용 프로....
  • EnumPrinters.
  • 알고 있어야 도움이 되....
  • Microsoft Windows XP....

최근에 달린 댓글

  • 좋은 자료 감사합니다.. Minjong Kim 08/09
  • 학습로드맵 잘 보고 갑.... Minjong Kim 08/09
  • 잘보고 갑니다 : ). hothead 07/16
  • 좋은 글 잘읽었습니다. ^^. Rhea君 05/06
  • 좋은 소프트웨어네여. montreal florist 01/12

최근에 받은 트랙백

  • Windows 시스템 실행파.... 김재호의 디지털보단 아... 02/14
  • 스레드만 사용하면 컴퓨.... 철없는강아지의 블로그 2008
  • 언제 다이어그램을 그려.... 너구리의 프로그래밍 세계 2007
  • 국내 웹환경에 기대를.... *~アスタリスク~ 2007
  • [플러그인] IS Flash Vi.... ISCUBIX.COM 2007

글 보관함

  • 2010/06 (1)
  • 2010/03 (2)
  • 2009/09 (1)
  • 2009/04 (2)
  • 2009/03 (5)

달력

«   2010/09   »
일 월 화 수 목 금 토
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    

링크

  • IT 용어사전.
  • Total : 288475
  • Today : 11
  • Yesterday : 245
Tattertools
Eolin
rss

달빛's blog is powered byTattertools1.5.3.1 : Adamantine
Skin by Nyangkum