HimomThep Posted August 15, 2011 Report Share Posted August 15, 2011 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 fecharagradeço se alguém poder ajuda muito obrigado!! Quote Link to comment Share on other sites More sharing options...
0 djfarinha Posted August 16, 2011 Report Share Posted August 16, 2011 (edited) 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 August 16, 2011 by djfarinha Quote Link to comment Share on other sites More sharing options...
0 Ace Stryker™ Posted August 16, 2011 Report Share Posted August 16, 2011 tente usar a função FindWindowvar H:THandle; begin H := FindWindow(nil,'Chat Line Brasil'); if H > 0 then SendMessage(H,WM_CLOSE,0,0); end;No lugar de Chat Line Brasil coloque o título da janela. Quote Link to comment Share on other sites More sharing options...
Question
HimomThep
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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.