Jump to content
Fórum Script Brasil
  • 0

Ajuda com comando pra fechar programa?


HimomThep

Question

Código: 
type 
  TForm1 = class(TForm) 
    ServerSocket1: TServerSocket; 
    procedure ServerSocket1ClientRead(Sender: TObject; 
      Socket: TCustomWinSocket); 
  private 
  H: THandle; 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 

var 
  Form1: TForm1; 

implementation 

{$R *.dfm} 

procedure TForm1.ServerSocket1ClientRead(Sender: TObject; 
  Socket: TCustomWinSocket); 
begin 
if Socket.ReceiveText='abrirserver' then begin 
ShellExecute(handle,'open',PChar('ChatLineBrasil.exe'), '','',Sw_minimize); 
end; 
if Socket.ReceiveText='fecharserver' then begin 
WinExec('taskkill /f /im ChatLineBrasil.exe', Wm_Close); 

end; 
end; 
end.

na hora de mandar fechar, não ta funcionando alguém poderia mi ajuda, já procurei mas não achei outra forma de mandar o programa fechar

agradeço se alguém poder ajuda muito obrigado!!

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Tente usar esta função

implementation 

uses Tlhelp32; 

function KillTask(ExeFileName: string): Integer; 
const 
PROCESS_TERMINATE = $0001; 
var 
ContinueLoop: BOOL; 
FSnapshotHandle: THandle; 
FProcessEntry32: TProcessEntry32; 
begin 
Result := 0; 
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 
FProcessEntry32.dwSize := SizeOf(FProcessEntry32); 
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); 
while Integer(ContinueLoop) <> 0 do 
begin 
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName)) or 
(UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then 
Result := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0), 
FProcessEntry32.th32ProcessID), 0)); 
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); 
end; 
CloseHandle(FSnapshotHandle); 
end; 
Para testar, deixe a calculadora do Windows aberta e faça no OnClick do botão: 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
KillTask('calc.exe'); 
end;

Edited by djfarinha
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...