Enumerate the process being running in the system and enforces the termination of the specified process

xiaoxiao2021-03-06  185

See your friend's post, collect it. [2002-2-19] Enumerates the process in which the system is running and terminates the specified process: add a TLHELP32 unit in the USES, add a Button and an Edit: procedure tForm1.Button1Click (Sender: TOBJECT) on the form. VAR ID: DWORD; // Process Identifier EXEFILE: STRING; // The file name of the process of the process RET: Boolean; SnapshotHandle: Thandle; // (System in the system or 碓, module, thread) snapshot of the process is PE32 : TProcessEntry32; // process entrance ProcHandle: HWND; handle begin exeFile // process: = LowerCase (Edit1.Text); // get a snapshot of the system handles all processes SnapshotHandle: = CreateToolHelp32Snapshot (TH32CS_SNAPPROCESS, 0); PE32. DWSIZE: = SIZEOF (PE32); // Get the first process in the snapshot to save its entry RET: = process32first (snapshothandle, pe32); while integer (re) <> 0 do begin if Pos (i, LowerCase (pe32.szexefile)> 0 THEN TRY ID: = pe32.th32processid; // Get the identity // open the specified process and save the handle of the process in ProChandle: = OpenProcess (process_all_access, // operation permission is All operation true, // handle can be inherited (? Do not understand?) ID); // Open the process IF Pro in the specified identifier Chandle <> 0 THEN TERMINATEPROCESS (ProChandle, 0); // Mandatory Termination This process (recommended using EXITPROCESS) Finally CloseHandle (ProChandle); end; ret: = process32next (snapshothandle, pe32); // Get the next process End END ;

转载请注明原文地址:https://www.9cbs.com/read-128559.html

New Post(0)