Kod: Tümünü seç
WinExec('C:\UsbAnahtar\Data\Lock.exe',sw_ShowNormal);
çağırdığımız exenin çalışmasını kill olarak nasıl durdururuz kapatırız.wi7 ve üstü versiyonlar için
Kod: Tümünü seç
WinExec('C:\UsbAnahtar\Data\Lock.exe',sw_ShowNormal);
Kod: Tümünü seç
unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
type
TFindWindowRec = record
ModuleToFind: string;
FoundHWnd: HWND;
end;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function EnumWindowsCallBack(Handle: hWnd; var FindWindowRec: TFindWindowRec): BOOL; stdcall;
var
Form1: TForm1;
FindWindowRec: TFindWindowRec;
implementation
{$R *.dfm}
uses
PsAPI;
function EnumWindowsCallBack(Handle: hWnd; var FindWindowRec: TFindWindowRec): BOOL; stdcall;
const
C_FileNameLength = 256;
var
WinFileName: string;
PID, hProcess: DWORD;
Len: Byte;
begin
Result := True;
SetLength(WinFileName, C_FileNameLength);
GetWindowThreadProcessId(Handle, PID);
hProcess := OpenProcess(PROCESS_ALL_ACCESS, False, PID);
Len := GetModuleFileNameEx(hProcess, 0, PChar(WinFileName), C_FileNameLength);
if Len > 0 then
begin
SetLength(WinFileName, Len);
if SameText(WinFileName, FindWindowRec.ModuleToFind) then
begin
Result := False;
FindWindowRec.FoundHWnd := Handle;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WinExec('C:\Windows\SysWOW64\Notepad.exe', SW_SHOWNORMAL);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
FindWindowRec.ModuleToFind := 'C:\Windows\SysWOW64\Notepad.exe';
FindWindowRec.FoundHWnd := 0;
EnumWindows(@EnumWindowsCallback, integer(@FindWindowRec));
if FindWindowRec.FoundHWnd <> 0 then
begin
SendMessage(FindWindowRec.FoundHWnd, WM_CLOSE, 0, 0);
end;
end;
end.
Kod: Tümünü seç
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 299
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 32
Top = 32
Width = 89
Height = 25
Caption = 'Notepad a'#231
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
Left = 32
Top = 72
Width = 89
Height = 25
Caption = 'Notepad kapat'
TabOrder = 1
OnClick = Button2Click
end
end