📄 unitkillprocess.pas
字号:
unit UnitKillProcess;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ShellAPI;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
const
PROCESS_TERMINATE = $0001; // OpenProcess constant
var
ProcessHandle: THandle; // a handle to the process
ProcessId: Integer; // the process identifier
TheWindow: HWND; // a handle to a window
begin
{retrieve a handle to the window whose process is to be closed}
TheWindow := FindWindow('TForm1', 'OpenProcess Example Window');
{retrieve the window's process identifier}
GetWindowThreadProcessId(TheWindow, @ProcessId);
{retrieve a handle to the window's process}
ProcessHandle := OpenProcess(PROCESS_TERMINATE, FALSE, ProcessId);
{display a message}
ShowMessage('Goodbye');
{terminate the spawned process}
TerminateProcess(ProcessHandle, 4);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
StartUpInfo: TStartUpInfo; // holds startup information
ProcessInfo: TProcessInformation; // holds process information
CurDir: string; // holds the current directory
begin
{initialize the startup info structure}
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
with StartupInfo do
begin
cb := SizeOf(TStartupInfo);
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := SW_SHOWNORMAL;
end;
{launch the spawned process}
CurDir := ExtractFilePath(ParamStr(0))+'ProjectOpenProcess.exe';
CreateProcess(PChar(CurDir), nil, nil, nil, False,
NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -