How in a service application to protect a process not to be closed?

There is a background process must have been running on the computer, but I don't know why this program often be rather baffling quietly dropped out, I would like to do a service application, in which periodic testing of the program is running, if not open it.
But service application of Delphi is not much, please help, pointing out the general process, such as the need to use the service application which event, best can simply write pseudo code, to help me sort out ideas.
Thank you!

Started by Broderick at February 08, 2016 - 8:36 PM

OnStart, a thread,
var //Global variables
hList : array [0..1] of THandle;
Threaded program
var
n : integer;
PID : DWORD;
begin
hList[0] := CreateEvent(NIL, False , False , NIL);
//if hList[0]=0 then error handling
while Not Terminated do begin
PID := GetProcessID('Process.Exe'); // this function to achieve
if PID=0 then begin
//Start the program
Continue;
end;
hList[1] := OpenProcess(PROCESS_ALL_ACCESS,False,PID);
if hList[1]=0 then begin
//Error handling
end;
n := WaitForMultipleObjects(2, @hList , False , DWORD(-1));
CloseHandle(hList[1]);
if n=AIT_OBJECT_0+1 then begin
//Restart the program
Continue;
end;
if n=WAIT_OBJECT_0 then Break;
//N= other error handling
end;
CloseHandle(hList[0]);
FreeOnTerminate := True;
end;

OnStop
begin
ThreadObject.Terminate;
SetEvent(hList[0]);
end;

Posted by Harrison at February 22, 2016 - 8:42 PM

Service to start the application in the currently logged in user session which is quite troublesome. Since the landlord Service well, you don't decide.
You write a daemon to monitor the background process on the line, do not have to service

Posted by Ed at January 01, 2017 - 8:27 PM

Thank you advice, I this is not required to "service to start the application in the current logged on user session", as long as the background.
Now the only not sure is, if the user is not logged on to administrator, will not affect the service opens the program? As in the win7 seems to have access to such things.

Posted by Broderick at January 02, 2017 - 7:35 PM