Special features and implementation methods!

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.