Clube da Programação e Hardware
Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.
Clube da Programação e Hardware

Tutorial, dicas, Programação, Hardware entre outros assuntos.
 
InícioInício  Últimas imagensÚltimas imagens  ProcurarProcurar  RegistarRegistar  Entrar  

 

 Reiniciar aplicativo Externo automatico?(Resolvido)

Ir para baixo 
2 participantes
AutorMensagem
LeandroBr




Mensagens : 12
Data de inscrição : 10/10/2012

Reiniciar aplicativo Externo automatico?(Resolvido) Empty
MensagemAssunto: Reiniciar aplicativo Externo automatico?(Resolvido)   Reiniciar aplicativo Externo automatico?(Resolvido) EmptyQua Out 10, 2012 8:18 am

preciso de um codigo para quando meu aplicativo executar um outro externo oculto ou não oculto, ae se este aplicativo externo for fechado por alguem ou até mesmo fechar sozinho, atomaticamente meu aplicativo renicie ele
tem como?

achei este codigo na internet, mas não cosigo adaptar ao que preciso.

Código:
procedure TForm1.VerificarExecucao;
var
MutexHandle: THandle;
hwind: HWND;

begin
MutexHandle := CreateMutex(nil, TRUE, 'MysampleAppMutex');
if MutexHandle <> 0 then
begin
if GetLastError = ERROR_ALREADY_EXISTS then
begin
MessageBox(0, 'Este programa já está em execução!', '', mb_IconHand);
CloseHandle(MutexHandle);
hwind := 0;
repeat
hwind := Windows.FindWindowEx(0, hwind, 'TApplication', 'appexterno');
until (hwind <> Application.Handle);
if (hwind <> 0) then
begin
Windows.ShowWindow(hwind, SW_SHOWNORMAL);
Windows.SetForegroundWindow(hwind);
end;
Halt;
end;
end;
end;


desde ja agradeço a todos.


Última edição por LeandroBr em Sáb Out 27, 2012 7:11 am, editado 1 vez(es)
Ir para o topo Ir para baixo
LeandroBr




Mensagens : 12
Data de inscrição : 10/10/2012

Reiniciar aplicativo Externo automatico?(Resolvido) Empty
MensagemAssunto: Re: Reiniciar aplicativo Externo automatico?(Resolvido)   Reiniciar aplicativo Externo automatico?(Resolvido) EmptyTer Out 16, 2012 7:55 am

Alguem sabe como resolver????
Ir para o topo Ir para baixo
Moderador
Admin



Mensagens : 44
Data de inscrição : 18/01/2011

Reiniciar aplicativo Externo automatico?(Resolvido) Empty
MensagemAssunto: Re: Reiniciar aplicativo Externo automatico?(Resolvido)   Reiniciar aplicativo Externo automatico?(Resolvido) EmptySex Out 26, 2012 9:03 pm

LeandroBr escreveu:
Alguem sabe como resolver????

se caso o seu aplicativo estiver em um só micro coloque um timer pra verificar de tempo em tempo, se o aplicativo
em processo no Windows.

use este codigo:

Código:
procedure TAutoStart_frm.CreateWin9xProcessList(List: TstringList);
var
hSnapShot: THandle;
ProcInfo: TProcessEntry32;
begin
if List = nil then Exit;
hSnapShot := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapShot <> THandle(-1)) then
begin
ProcInfo.dwSize := SizeOf(ProcInfo);
if (Process32First(hSnapshot, ProcInfo)) then
begin
List.Add(ProcInfo.szExeFile);
while (Process32Next(hSnapShot, ProcInfo)) do
List.Add(ProcInfo.szExeFile);
end;
CloseHandle(hSnapShot);
end;

end;

Código:
procedure TAutoStart_frm.GetProcessList(var List: TstringList);
var
ovi: TOSVersionInfo;
begin
if List = nil then Exit;
ovi.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
GetVersionEx(ovi);
case ovi.dwPlatformId of
VER_PLATFORM_WIN32_WINDOWS: CreateWin9xProcessList(List);
VER_PLATFORM_WIN32_NT: CreateWin9xProcessList(List);
end
end;

Código:
function TAutoStart_frm.EXE_Running(FileName: string; bFullpath: Boolean): Boolean;
var
i: Integer;
MyProcList: TstringList;
begin
MyProcList := TStringList.Create;
try
GetProcessList(MyProcList);
Result := False;
if MyProcList = nil then Exit;
for i := 0 to MyProcList.Count - 1 do
begin
if not bFullpath then
begin
if CompareText(ExtractFileName(MyProcList.Strings[i]), FileName) = 0 then
Result := True
end
else if CompareText(MyProcList.strings[i], FileName) = 0 then Result := True;
if Result then Break;
end;
finally
MyProcList.Free;
end;
{exemplo de com usar}
procedure TAutoStart_frm.sBitBtn3Click(Sender: TObject);
begin
if apache.Checked then
if EXE_Running('apache.exe', False) then
else
ShellExecute(handle, 'open', 'Apache.bat', pchar(''),'Apache_Server', SW_SHOWNORMAL);
end;



























Ir para o topo Ir para baixo
https://netdicas.forumeiros.com
LeandroBr




Mensagens : 12
Data de inscrição : 10/10/2012

Reiniciar aplicativo Externo automatico?(Resolvido) Empty
MensagemAssunto: Re: Reiniciar aplicativo Externo automatico?(Resolvido)   Reiniciar aplicativo Externo automatico?(Resolvido) EmptySáb Out 27, 2012 7:11 am

Moderador escreveu:
LeandroBr escreveu:
Alguem sabe como resolver????

se caso o seu aplicativo estiver em um só micro coloque um timer pra verificar de tempo em tempo, se o aplicativo
em processo no Windows.

use este codigo:

Código:
procedure TAutoStart_frm.CreateWin9xProcessList(List: TstringList);
var
hSnapShot: THandle;
ProcInfo: TProcessEntry32;
begin
if List = nil then Exit;
hSnapShot := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapShot <> THandle(-1)) then
begin
ProcInfo.dwSize := SizeOf(ProcInfo);
if (Process32First(hSnapshot, ProcInfo)) then
begin
List.Add(ProcInfo.szExeFile);
while (Process32Next(hSnapShot, ProcInfo)) do
List.Add(ProcInfo.szExeFile);
end;
CloseHandle(hSnapShot);
end;

end;

Código:
procedure TAutoStart_frm.GetProcessList(var List: TstringList);
var
ovi: TOSVersionInfo;
begin
if List = nil then Exit;
ovi.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
GetVersionEx(ovi);
case ovi.dwPlatformId of
VER_PLATFORM_WIN32_WINDOWS: CreateWin9xProcessList(List);
VER_PLATFORM_WIN32_NT: CreateWin9xProcessList(List);
end
end;

Código:
function TAutoStart_frm.EXE_Running(FileName: string; bFullpath: Boolean): Boolean;
var
i: Integer;
MyProcList: TstringList;
begin
MyProcList := TStringList.Create;
try
GetProcessList(MyProcList);
Result := False;
if MyProcList = nil then Exit;
for i := 0 to MyProcList.Count - 1 do
begin
if not bFullpath then
begin
if CompareText(ExtractFileName(MyProcList.Strings[i]), FileName) = 0 then
Result := True
end
else if CompareText(MyProcList.strings[i], FileName) = 0 then Result := True;
if Result then Break;
end;
finally
MyProcList.Free;
end;
{exemplo de com usar}
procedure TAutoStart_frm.sBitBtn3Click(Sender: TObject);
begin
if apache.Checked then
if EXE_Running('apache.exe', False) then
else
ShellExecute(handle, 'open', 'Apache.bat', pchar(''),'Apache_Server', SW_SHOWNORMAL);
end;


Valeu a pena esperar, Muito obrigado.
Ir para o topo Ir para baixo
Conteúdo patrocinado





Reiniciar aplicativo Externo automatico?(Resolvido) Empty
MensagemAssunto: Re: Reiniciar aplicativo Externo automatico?(Resolvido)   Reiniciar aplicativo Externo automatico?(Resolvido) Empty

Ir para o topo Ir para baixo
 
Reiniciar aplicativo Externo automatico?(Resolvido)
Ir para o topo 
Página 1 de 1
 Tópicos semelhantes
-
» DBGrid com Progressbar (Resolvido)
» Botão gravar [Resolvido]
» Alterar cores do PageControl (Delphi) (Resolvido )
» como Re-indexar em tabela paradox (Resolvido)
» Consulta de registros por dois edit? ( Resolvido)

Permissões neste sub-fórumNão podes responder a tópicos
Clube da Programação e Hardware :: PROGRAMAÇÃO :: Delphi-
Ir para: