C + + gadgets. Close process

Source: Internet
Author: User
Tags strcmp

1, according to the process name to end the corresponding process, exe name: "__killprocessbyname_console_vc6.exe".

Project saved in Baidu Cloud (CodeSkill33)--All Files-->util_ My gadget _ small software--> VS08_VC6---Process Name _ Enumeration Process _ End process--__ killprocessbyname_console_vc6__?????. RAR

2. Code:

//__killprocessbyname_console_vc6.cpp:defines the entry point for the console application.//#include"stdafx.h"#include<stdlib.h>#include<stdio.h>#include<windows.h>#include<TlHelp32.h>BOOLMatchprocessname (Char* _pcprocnamesnapshot,intargcChar* argv[],int*_piidxout) {     for(intI=1; i<argc; i++)    {        //strncmp are case-most grateful.//and a strcmp .        if(!strnicmp (_pcprocnamesnapshot, Argv[i], strlen (Argv[i])) {            *_piidxout =i; return true; }    }    return false;}intMainintargcChar*argv[]) {    if(ARGC <2) {printf ("In the program's command-line arguments, enter the name of the process that requires kill \ n"); return 0; } printf ("The name of the process you want to end is: \ n");  for(intI=1; i<argc; i++) {printf ("\t%s\n", Argv[i]); } printf ("Press any key to continue, or close this window to exit the program \ n"); System ("Pause"); int*pikills =New int[ARGC]; memset (Pikills,0, ARGC *sizeof(int));//ZC: Enumerating ProcessesHANDLE hsnapshot = CreateToolhelp32Snapshot (th32cs_snapprocess,0); PROCESSENTRY32 processEntry32= {0}; Processentry32.dwsize=sizeof(PROCESSENTRY32); BOOL bOk= Process32First (hSnapShot, &processEntry32);  while(bOk) {//wprintf (L "%ws,%d\n", Processentry32.szexefile, Processentry32.th32processid);        intIIDX =0; if(Matchprocessname (Processentry32.szexefile, argc, argv, &iIdx)) {DWORD ProcessID=Processentry32.th32processid; //Break ; //ZC: Forced End Process                        {                            //strcmp Wide character version wcscmp: Compare strings (case sensitive)//_stricmp Wide character version _wcsicmp: Comparing strings (case insensitive)HANDLE hprocess = OpenProcess (Process_terminate,false, ProcessID); if(hprocess = =NULL) {printf ("openprocess err:%d\n",:: GetLastError ()); System ("Pause"); }                            Else{BOOL Bresult= TerminateProcess (hprocess,0); if(!bresult) {printf ("terminateprocess err:%d\n",:: GetLastError ()); System ("Pause"); }                                Else{Pikills[iidx]++; } }}} bOk= Process32Next (hSnapShot, &processEntry32);    }:: CloseHandle (hSnapShot);  for(intj=1; j<argc; J + +) {printf ("\t%s was killed. \t==>%d processes \ n", Argv[j], pikills[j]); } System ("Pause"); return 0;}

3.

4.

5.

C + + gadgets. Close process

Related Article

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.