Home > Back-end >  Do a daemon detect whether another exe running didn't run on him
Do a daemon detect whether another exe running didn't run on him

Time:09-21

Daemon to hidden, of course, don't turn off to a train of thought by user

Began to want to be a Windows service application later found can't deal with interface exe


CodePudding user response:

do a daemon detect whether another exe running without running start he
 function TWin32Utils. Set (const AExeName: String) : Boolean; 
Var
SzExeName: String;
HSnapshot: THandle;
REntry32: TProcessEntry32;
BExists: Boolean;
The begin
Result:=False;
SzExeName:=ExtractFileName (AExeName);
HSnapshot:=CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
Try
REntry32. DwSize:=Sizeof (rEntry32);
BExists:=Process32First (hSnapshot rEntry32);
While bExists do
The begin
If Pos (UpperCase (rEntry32 szExeFile), UpperCase (szExeName)) & gt; 0 then
The begin
Result:=True;
Break;
end;
BExists:=Process32Next (hSnapshot rEntry32);
end;
The finally
The CloseHandle (hSnapshot);
end;
end;


of course daemon hidden by users easily turn off to a way of thinking
do A guard each other solution, A program in A timer, and regularly check and start the program B, B also has A timer in the program, check and started A program

began to want to be a Windows service application later found can't deal with interface exe
TService. Interactive:=True;

CodePudding user response:

Thanks to the upstairs to answer

I began to do is a Windows service application timer to detect whether the program run B
Interactive:=True;

Tests found ShellExecute (0, the 'open', 'd: \ mytest. Exe, nil, nil, SW_SHOWNORMAL); When the program calls B complains (an estimated interface B)


CodePudding user response:

Winexec try, I use winexec is no problem

CodePudding user response:

Winexec (' d: \ mytest. Exe, sw_normal);

CodePudding user response:

reference 4 floor hnlg81004 response:
winexec (' d: \ mytest. Exe, sw_normal);


Test under what operating system are you? Win2003 test under Windows 7 B program interface can display

CodePudding user response:

Now the question is:
Win2003 test under Windows 7 B program interface can't display but exist in the process of

They would (if B program work alone can be display to run B)

CodePudding user response:

My partner server through which every 10 seconds test server is running, if close to restart the server,

CodePudding user response:

According to gobiz ideas should be able to,

Process there were, in reality it is effect?

CodePudding user response:

refer to 7th floor lyhoo163 response:
my partner of the server, through which every 10 seconds test server is running, if close to restart the server,


What's your partner is a Windows service server? Give your mind

CodePudding user response:

Can use mutexes, whether exe program running,

CodePudding user response:

1, the program is set to launch in pattern, boot is activated;
2, the program USES the VCL window, tray form at ordinary times, when it is necessary to open the window,
3, timing for 5 minutes: search EXE process, search, restart the EXE,


CodePudding user response:

MArk

CodePudding user response:

User interaction under Windows 7 desktop cannot come true,
Can do a separate service to protect your program,


.exe ';
end;



Procedure TEDSClientMonitorService. ServiceStop (Sender: TService;
Var Stopped: Boolean);
The begin

EnableDebugPrivilege;
KillTask (FLocalFileName);
IntAndSet (' Cose ');

The CloseHandle (Mh);
Stopped:=true;
//WTSSendMessage (0, WTSGetActiveConsoleSessionId (), 'ss', 4, 'DDDDD, 12, 0, 0, s, false);
end;

Procedure TEDSClientMonitorService. SetDescription (const Desc: string).
Var
Reg: TRegistry;
The begin
Reg:=TRegistry. Create;
Try
With reg do begin
RootKey:=HKEY_LOCAL_MACHINE;
If OpenKey (' SYSTEM \ CurrentControlSet \ Services \ '+ Name, false) then
The begin
WriteString (' Description 'Desc);
end;
CloseKey;
end;
The finally
Reg. Free;
end;

end;

Procedure TEDSClientMonitorService. MonitorTimer (Sender: TObject);
Var
F: string;
Hh, MI: string;
Nowtime: TDatetime;
I: integer;
The begin
Monitor. Enabled:=False;
The Monitor. The Interval:=1000;
Try
Nowtime:=now;
DateTimeToString (hh, 'hh, nowtime);
DateTimeToString (mi, 'nn, nowtime);
//every time to restart
If (hh='13') and (mi='30') then
The begin
Sleep (60000);
ReStart ();
End
The else
The begin
Automatic restart//for more than a day
If round (1000) (Gettickcount - Fcur)/& gt; Then 86400
The begin
Sleep (60000);
ReStart ();
The exit;
end;
If ReadMsg='Cose' then
The begin
Wlog (' user invokes close services);
The exit;
end;
I:=FindProcessID (FLocalFileName);

F:=ExtractFilePath (ParamStr (0)) + FLocalFileName;
If I=0 then
The begin
LaunchAppIntoDifferentSession (Pchar (f));
End
The else
The begin
If I & gt; 1 then
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related