C + + obtains all processes of the current system

Source: Internet
Author: User

FILE *file;
Fopen_s (&file, "E:\\c++pro\\allprocess\\allprocess.txt", "A +");
TCHAR c[] = {L "cmd.exe"}; Define the string and initialize it, C is 8 length, the last end has ' s ', define a character as ' X ',
HANDLE HANDLE; Defining CreateToolhelp32Snapshot System Snapshot handles
HANDLE Handle1; Define the process handle to end
Handle = CreateToolhelp32Snapshot (th32cs_snapprocess, 0);//get system snapshot handle
PROCESSENTRY32 *info; Define PROCESSENTRY32 structure word refers to
dwsize members of the PROCESSENTRY32 structure are set to sizeof (PROCESSENTRY32)
info = new PROCESSENTRY32;
info->dwsize = sizeof (PROCESSENTRY32);
Call the Process32First function once to get the list of processes from the snapshot
Process32First (handle, info);
Call Process32Next repeatedly until the function returns FALSE
while (Process32Next (handle, info)! = FALSE)
{
info->szexefile; Point to Process name
Wcout << info->szexefile << Endl;
fprintf (file, "%ls", info->szexefile);
strcmp string comparison function to end the same
if (wcscmp (c, info->szexefile) = = 0)
{
MessageBox (NULL, Info->szexefile, TEXT ("Hellomsg"), 0);
Process_terminate indicates open for end operation, False= inheritable, info->th32processid= process ID
Handle1 = OpenProcess (Process_terminate, FALSE, Info->th32processid);
End Process
TerminateProcess (handle1, 0);
}
}
fclose (file);

C + + obtains all processes of the current system

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.