| Clube da Programação e Hardware Tutorial, dicas, Programação, Hardware entre outros assuntos. |
| | Reiniciar aplicativo Externo automatico?(Resolvido) | |
| | Autor | Mensagem |
---|
LeandroBr
Mensagens : 12 Data de inscrição : 10/10/2012
| Assunto: Reiniciar aplicativo Externo automatico?(Resolvido) Qua 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) | |
| | | LeandroBr
Mensagens : 12 Data de inscrição : 10/10/2012
| Assunto: Re: Reiniciar aplicativo Externo automatico?(Resolvido) Ter Out 16, 2012 7:55 am | |
| Alguem sabe como resolver???? | |
| | | Moderador Admin
Mensagens : 44 Data de inscrição : 18/01/2011
| Assunto: Re: Reiniciar aplicativo Externo automatico?(Resolvido) Sex 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; | |
| | | LeandroBr
Mensagens : 12 Data de inscrição : 10/10/2012
| Assunto: Re: Reiniciar aplicativo Externo automatico?(Resolvido) Sá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.
| |
| | | Conteúdo patrocinado
| Assunto: Re: Reiniciar aplicativo Externo automatico?(Resolvido) | |
| |
| | | | Reiniciar aplicativo Externo automatico?(Resolvido) | |
|
Tópicos semelhantes | |
|
| Permissões neste sub-fórum | Não podes responder a tópicos
| |
| |
| |
|