Enumerate all processes in the current system with snapshots

Source: Internet
Author: User
Tags sprintf

How to enumerate all the processes in the current system with snapshots, more friends asked this question recently, so simply posted up to forget. Oh. :D

Add a ListView to the form, set its viewstyle to VSReport, add a three column to ListView, and add a button.

#include <tlhelp32.h>
#include "stdio.h"
void __fastcall Tmainform::button1click (tobject *sender)
{
Find each process and display it.
HANDLE snapshot;
PROCESSENTRY32 ProcessInfo;
processinfo.dwsize = sizeof (ProcessInfo);
snapshot = CreateToolhelp32Snapshot (th32cs_snapprocess, 0);
if (snapshot = NULL)
return;
BOOL status = Process32First (snapshot, &processinfo);
while (status)
{
Tlistitem *li = Listview1->items->add ();
String buffer;
int length;
Buffer. SetLength (512);
Length = sprintf (Buffer.c_str (), "%08x", Processinfo.th32processid);
Buffer. SetLength (length);
li->caption = buffer;
Buffer. SetLength (512);
Length = sprintf (Buffer.c_str (), "%08x", Processinfo.th32parentprocessid);
Buffer. SetLength (length);
Li->subitems->add (buffer);
Li->subitems->add (Processinfo.szexefile);
Status = Process32Next (snapshot, &processinfo);
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.