Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Killing Program/Process Before Shutdown

Posted on 1998-09-11
4
146 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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