Solved

Killing Program/Process Before Shutdown

Posted on 1998-09-11
4
143 Views
Last Modified: 2010-04-06
I Need To Kill Program/Service/Process Before Win9x Shutdown....  how i do that using Delphi ?
i don't know much Delphi...
0
Comment
Question by:natanp
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1339489
Here is an example........
---------
interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    function HookProc(var Message: TMessage): boolean;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

const
  FlagFileName = 'C:\Flag.Fil';

procedure CreateFlagFile;
var
  F: System.Text;
begin
  System.Assign(F, FlagFileName);
  System.Rewrite(F);
  Writeln(F, 'This is a dummy flag file');
  System.Close(F);
end;

procedure KillFlagFile;
var
  F: File;
begin
  System.Assign(F, FlagFileName);
  System.Erase(F);
end;

procedure MyExitProc; far;
begin
  KillFlagFile;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.HookMainWindow(HookProc);
end;

function TForm1.HookProc(var Message: TMessage): boolean;
begin
  Result := false;
  if Message.Msg = WM_EndSession then
  begin
    if WordBool(Message.wParam) then
    begin
      { Windows is closing down - clean up!! }
       Halt;
    end;
  end;
end;

initialization
  CreateFlagFile;
  AddExitProc(MyExitProc);
end.
-----------
Regards,
Viktor Ivanov
0
 
LVL 7

Expert Comment

by:Motaz
ID: 1339490
When Windows 95 shut down it will shut all applications and process so that if you write Delphi program to detect windows shut down and close all other applications; it dosn't mean any thing becuase windows automaticly shut down this programs when it shut down.

Motaz from Sudan.
motaz1@yahoo.com
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339491
Natan maybe needs to clean up something when win shuts down...

//viktor
0
 
LVL 7

Expert Comment

by:Motaz
ID: 1339492
Yes, that is right viktornet.

Motaz.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now