diyerdre Posted April 22, 2015 Report Share Posted April 22, 2015 Ola, sou novo por aqui, gostaria de saber como faço para criar um botão e quando eu clicar neste botão, ele execute um arquivo .BAT externo e deixe em backgroud, e outro botão para matar o mesmo processo. OBRIGADO. Quote Link to comment Share on other sites More sharing options...
0 Jhonas Posted April 23, 2015 Report Share Posted April 23, 2015 exemplo unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function ExecAndWait(const FileName: string; const CmdShow: Integer): Longword; var { by Pat Ritchey } zAppName: array[0..512] of Char; zCurDir: array[0..255] of Char; WorkDir: string; StartupInfo: TStartupInfo; ProcessInfo: TProcessInformation; AppIsRunning: DWORD; begin StrPCopy(zAppName, FileName); GetDir(0, WorkDir); StrPCopy(zCurDir, WorkDir); FillChar(StartupInfo, SizeOf(StartupInfo), #0); StartupInfo.cb := SizeOf(StartupInfo); StartupInfo.dwFlags := STARTF_USESHOWWINDOW; StartupInfo.wShowWindow := CmdShow; if not CreateProcess(nil, zAppName, // pointer to command line string nil, // pointer to process security attributes nil, // pointer to thread security attributes False, // handle inheritance flag CREATE_NEW_CONSOLE or // creation flags NORMAL_PRIORITY_CLASS, nil, //pointer to new environment block nil, // pointer to current directory name StartupInfo, // pointer to STARTUPINFO ProcessInfo) // pointer to PROCESS_INF then Result := WAIT_FAILED else begin while WaitForSingleObject(ProcessInfo.hProcess, 0) = WAIT_TIMEOUT do begin Application.ProcessMessages; Sleep(50); end; WaitForSingleObject(ProcessInfo.hProcess, INFINITE); GetExitCodeProcess(ProcessInfo.hProcess, Result); CloseHandle(ProcessInfo.hProcess); CloseHandle(ProcessInfo.hThread); end; end; procedure TForm1.Button1Click(Sender: TObject); var comando : string; begin comando := 'C:\LIMPA.BAT'; ExecAndWait(comando, SW_HIDE); showmessage('comando executado e concluido'); end; end. abraço Quote Link to comment Share on other sites More sharing options...
Question
diyerdre
Ola, sou novo por aqui, gostaria de saber como faço para criar um botão e quando eu clicar neste botão, ele execute um arquivo .BAT externo e deixe em backgroud, e outro botão para matar o mesmo processo.
OBRIGADO.
Link to comment
Share on other sites
1 answer 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.