[Cpp]
// Testlog. cpp: defines the entry point of the console application.
//
# Include "stdafx. h"
# Include <iostream>
# Include <Windows. h>
# Include <TlHelp32.h>
Using namespace std;
Int _ tmain (int argc, _ TCHAR * argv [])
{
// HMODULE Mymhandle;
// _ Tsystem (L "calc.exe ");
// Mymhandle = GetModuleHandle (0 );
// TerminateProcess (handle1, 0 );
//
// Int RetValue = GetLastError ();
TCHAR c [] = {L "cmd.exe"}; // defines the string and initializes it. c is an 8-length string ending with '\ 0' and defines a character as 'x ',
HANDLE handle; // defines the snapshot HANDLE of the createconlhelp32snapshot system.
HANDLE handle1; // defines the process HANDLE to end
Handle = createconlhelp32snapshot (TH32CS_SNAPPROCESS, 0); // obtain the System Snapshot handle
PROCESSENTRY32 * info; // define the PROCESSENTRY32 Structure
// Set the dwSize Member of the PROCESSENTRY32 structure to sizeof (PROCESSENTRY32)
Info = new PROCESSENTRY32;
Info-> dwSize = sizeof (PROCESSENTRY32 );
// Call the Process32First function to obtain the process list from the snapshot.
Process32First (handle, info );
// Call Process32Next repeatedly until the function returns FALSE.
While (Process32Next (handle, info )! = FALSE)
{
Info-> szExeFile; // point to the process name
// The strcmp string comparison function must end with the same
If (wcscmp (c, info-> szExeFile) = 0)
{
// MessageBox (NULL, info-> szExeFile, TEXT ("HelloMsg"), 0 );
// PROCESS_TERMINATE indicates that the end operation is enabled, FALSE = can be inherited, info-> th32ProcessID = process ID
Handle1 = OpenProcess (PROCESS_TERMINATE, FALSE, info-> th32ProcessID );
// End the process
TerminateProcess (handle1, 0 );
}
}
CloseHandle (handle );
Return 0;
}
// Testlog. cpp: defines the entry point of the console application.
//
# Include "stdafx. h"
# Include <iostream>
# Include <Windows. h>
# Include <TlHelp32.h>
Using namespace std;
Int _ tmain (int argc, _ TCHAR * argv [])
{
// HMODULE Mymhandle;
// _ Tsystem (L "calc.exe ");
// Mymhandle = GetModuleHandle (0 );
// TerminateProcess (handle1, 0 );
//
// Int RetValue = GetLastError ();
TCHAR c [] = {L "cmd.exe"}; // defines the string and initializes it. c is an 8-length string ending with '\ 0' and defines a character as 'x ',
HANDLE handle; // defines the snapshot HANDLE of the createconlhelp32snapshot system.
HANDLE handle1; // defines the process HANDLE to end
Handle = createconlhelp32snapshot (TH32CS_SNAPPROCESS, 0); // obtain the System Snapshot handle
PROCESSENTRY32 * info; // define the PROCESSENTRY32 Structure
// Set the dwSize Member of the PROCESSENTRY32 structure to sizeof (PROCESSENTRY32)
Info = new PROCESSENTRY32;
Info-> dwSize = sizeof (PROCESSENTRY32 );
// Call the Process32First function to obtain the process list from the snapshot.
Process32First (handle, info );
// Call Process32Next repeatedly until the function returns FALSE.
While (Process32Next (handle, info )! = FALSE)
{
Info-> szExeFile; // point to the process name
// The strcmp string comparison function must end with the same
If (wcscmp (c, info-> szExeFile) = 0)
{
// MessageBox (NULL, info-> szExeFile, TEXT ("HelloMsg"), 0 );
// PROCESS_TERMINATE indicates that the end operation is enabled, FALSE = can be inherited, info-> th32ProcessID = process ID
Handle1 = OpenProcess (PROCESS_TERMINATE, FALSE, info-> th32ProcessID );
// End the process
TerminateProcess (handle1, 0 );
}
}
CloseHandle (handle );
Return 0;
}