Special features and implementation methods! Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiAPI/html/delphi_20061118141925203.html
Is there a simple way to monitor whether an EXE file is running or dead?
Restart the EXE immediately. Program . Can I change the registry ???
I have attached a time-based restart of the EXE source program;
Http://www.sojibar.com/images/upfile/run2006-10-14.rar
By the way, I want a better method. Thank you!
After the EXE process is created, a structure object about the process information is obtained by using the process monitoring method. Call getexitcodeprocess. If the exit code is still_active, the process is still running. Otherwise, the process has been disabled.
Woshihaoge thank you!
Is it complicated.
Generally, process monitoring is used! This is what many Trojans or rogue software do!
<B> Can you elaborate? </B>
Woshihaoge thank you!
According to your method, I implemented it. I don't know if it will take effect if the program is suspended. Not tested yet.
Code :
Public
{Public declarations}
Si: tstartupinfo;
Pi: tprocessinformation;
Add form. Show:
Fillchar (Si, sizeof (SI), #0 );
With Si Do
Begin
CB: = sizeof (SI );
Dwflags: = startf_usestdhandles or startf_useshowwindow;
Lptitle: = nil; // pchar ('gxtvodserver ');
Wshowwindow: = sw_show;
End;
// Application. processmessages;
CreateProcess (pchar (exefile), nil, true, idle_priority_class, nil, nil, Si, Pi );
// Myhandle: = OpenProcess (process_terminate, true, Pi. dwprocessid );
// Start monitoring
Timer1.enabled: = true;
Procedure tform1.timer1timer (Sender: tobject );
VaR
Exitcode: DWORD;
Begin
// Handle: = OpenProcess (process_terminate, true, Pi. dwprocessid );
Getexitcodeprocess (PI. hprocess, exitcode );
If not (exitcode = still_active) Then // still_active
Begin
// Showmessage ('process disabled ');
Timer1.enabled: = false;
If chksetting () then
Begin
Restartsvr (); // start service
End;
End;
It's not a Trojan.
Haha, the code you wrote is very correct.
In fact, the most stupid method is to constantly use the findwindow function in a timer control event to check whether your running program exists. If it does not exist, use ShellExecute to execute it.
The last one!
The findwindow is not accurate. Do not kill the process!