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