Solved

How to prevent windows from closing my Application using  (End Process & End Task) from Windows Task Manager using Delphi

Posted on 2009-05-17
26
1,799 Views
Last Modified: 2012-05-07
How to prevent windows from closing my Application using  (End Process & End Task) from Windows Task Manager using Delphi??

  OS: XP or Vista.

Thanks in Advance.
0
Comment
Question by:i7mad
  • 8
  • 7
  • 4
  • +3
26 Comments
 
LVL 13

Expert Comment

by:ThievingSix
ID: 24405686
Checkout the demos in madCodeHook at madshi.net

Basically you'll need to do a system wide hook on TerminateProcess. It's no simple job even with madCodeHook.

These links might also help:
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_22685098.html
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21255715.html
http://www.swissdelphicenter.ch/torry/showcode.php?id=1240
http://w-shadow.com/blog/2006/09/21/hiding-from-nt-taskmanager/
0
 
LVL 90

Expert Comment

by:John Hurst
ID: 24406062
And when your program fails, what are we users supposed to do? I only use applications that behave nicely within a standard Windows world (customer talking here). ... Thinkpads_User
0
 

Author Comment

by:i7mad
ID: 24406305

thinkpads_user:

this is my own application and this is my job to develop applications and get money.

I just wanted to prevent illegal use of my application
0
 
LVL 90

Expert Comment

by:John Hurst
ID: 24406379
Using Task Manager to kill a defective program is not illegal use. When I evaluate a product that might be used by 30 or 40 users, I check it against common legal usage. If it gets in the way (as you describe in your first post) I will not buy it or recommend it. Words to the wise, and of course, proceed as you wish. ... Thinkpads_User
0
 

Author Comment

by:i7mad
ID: 24406410
according to my method of protecting my application from illegal use, the application should close correctly in order to save some results for the next use.
0
 
LVL 90

Expert Comment

by:John Hurst
ID: 24406542
I know that. I think you are missing my point. ALL applications fail. Yours will too. It is not a matter of IF, it is a matter of WHEN, even if not your doing. When that happens I have no recourse except Task Manager -> Quit application or process. Your way, I must restart the entire machine when your application fails. Counter productive for me.

I realize we are on opposite sides of the street, but you are the seller, and I am the buyer with cash burning a hole in my pocket. Even so, I evaluate carefully and stringently.

And I have NEVER seen the application that didn't fail for one reason or another (even if my doing through, say lack of memory). But I do demand to have control over my own machine. When vendors take control (forbid back arrow, forbid reinstall, forbid forcing the app to close, and so on) then I just go elsewhere.
... Thinkpads_User
0
 
LVL 31

Expert Comment

by:moorhouselondon
ID: 24407117
There's the On/Off button (whisper) which I occasionally hold in for 5 seconds to kill everything.

If you are concerned about saving results, when starting the program set an entry somewhere to indicate "Program Started", and when cloising the program delete this entry after saving the settings you mentioned.  When starting the program, find out whether the "program started" entry, file, or whatever it is, exists - if it does then do whatever housekeeping is needed to recover from abnormal shutdown e.g., reindexing dbase indexes.
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24408079
you have been asking this question over and over.
and you will never get the answer you want.

you are probably not saving the changes in the correct way.
You can kill any of my applications, at any time, i don't loose any data,
except the last transaction.
And nobody wants to keep a transaction of which the result is unsure.

don't tell me you are using a timer to save your data frequently ???
0
 

Author Comment

by:i7mad
ID: 24409373

Geert_Gruwez:

  This is the first time I am asking this question btw.

    I am saving the changes on Form Close/Destroy Events. and my applications like yours. You can kill any of my applications, at any time, i don't loose any data, except the last transaction.

my question is because this last transaction. and also for Users Log Data.

I am saving User Name , Last Login time, Last Logout time.

  how to save the last logout time for example when windows kills your application ?
0
 
LVL 31

Expert Comment

by:moorhouselondon
ID: 24409412
As Geert implies, if you use a Timer component, you can commit the username, login name and logout time to a "persistent" location every time the Timer fires.  By persistent I mean the registry, a file, or a database.  You might say that the user is still logged in when you store the logout time like that, but you can differentiate a true logout from a timer generated one by having an extra piece of info - a boolean, which says whether the logout was an actual explicit logout or whether it was generated by the timer whilst the user was still logged in.
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 24409423
>> how to save the last logout time for example when windows kills your application ?
you can't ... as you don't log out !

unless ... what database is it ?
you can only do that on a database level (if it supports this)
0
 

Author Comment

by:i7mad
ID: 24409484

Geert_Gruwez:

 BDE, Paradox tables.
0
 

Author Comment

by:i7mad
ID: 24409495

moorhouselondon:

 yes I have that boolean named it SavingDone. and a value in my application options file named it: Safe Shutdown. if its true then last time my application closed safely, otherwise no.

  All I want to make garuntee 100% that everything saved correctly
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 31

Expert Comment

by:moorhouselondon
ID: 24409584
If using bde, paradox you really need to make the table active, post the data, then close it.  If the table is posted to, then the power is turned off, the data may not have been committed to the table.  Closing the table flushes the posted record from memory into the table on the hard drive.  Failure to do this may mean that the last record is not in the table, and may also corrupt the table.
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24486591
it's actually impossible for isam tables like paradox / dbase to do this.
you need a database with a database engine for this like oracle/mssql/firebird/interbase
these databases store a entry for each connection and can run a job periodically to check these connections
this job can determine via a ping or something a like if the connection is still active and thus update the database when the connection is lost
0
 
LVL 39

Expert Comment

by:abel
ID: 24525267
Just came across this thread because of a likewise question elsewhere. It seems that the asker is afraid of not being able to save anything when the user clicks "End Process". One common way of preventing loss of data when an unconditional kill occurs is to use a second process that monitors the first, possibly started as a service. This process then keeps handles open to objects not saved. It is however a lot of work and for someone deliberately killing a process, who deliberately sacrifices unsaved data, I'm not sure it is worth the trouble. But it is possible, though.

Alternatively, but I haven't tried this: the TerminateProcess API call which is done by TaskMgr is first notifying each DLL that the process is terminating (according to API docs). You may be able to act on that from inside your DLL (yet to be created) and save the state of your program.

just my 2p,

-- Abel --
0
 
LVL 39

Expert Comment

by:abel
ID: 24525328
And, on a side note, from your question it also says "End Task", which is a simple WM_QUIT like any other and you can react to that and save anything before your applications exits.
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24525817
@abel
when killing a process with the task manager from the processes list, the app does not get notified
from the applications list, it does
0
 

Author Comment

by:i7mad
ID: 24525863
Well guys,

  The answer for this question should be the same  answer for This Question:

"How Can I achieve 100% of No-Data-Loss, when cases such as electricity-cut , or unexpected & sudden PC shutdown"
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24525889
100% of No-Data-Loss --> never

electricity-cut is very simple ... use a UPS: Uninterruptable Power Supply

You will still not be able to prevent that with like ... a jumbo jet flying into server room (remember Twin Towers ?)
0
 

Author Comment

by:i7mad
ID: 24525950
lol Greet yes I remember them very well.

  I have my kid always play with the PSU power button and I have no UPS at home. tow days a go I worked like for 3 hours on a delphi source code and didn't save anything, I went to the bathroom and when I back ... a black screen and the pc is turned off
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24525957
sounds like my wife :)
0
 
LVL 39

Expert Comment

by:abel
ID: 24525968
> when killing a process with the task manager from the processes list, the app does not get notified

"End task" >>> you can still react. Is equal to the little cross, or alt-F4, or WM_QUIT (this is the Applications list, not the Processes list).

"End process" >>> you can do little about it, apart from the DLL-approach, the API hook explained in the beginning of this thread, and the "process monitor" approach ("end process" is in the Processes list)

indeed, 100% guarantee is not possible, but you can get close. Certain medical systems, embedded software for security, i.e., cars, railway crossovers, nuclear power plants, or simpler, the software inside your washing machine will go to great lengths not to have data loss they cannot recover from. But these systems won't run windows ;-)
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24525981
these systems are mostly plc systems
they use EEPROMS ... totally different
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24525988
i would advice a good whipping, that allways helps as a reminder to "stay off !"
0
 
LVL 39

Expert Comment

by:abel
ID: 24526514
haha, indeed.

> they use EEPROMS ... totally different

well, some indeed, but many others run on java embedded os's. But that's a different discussion indeed.

Should I also whip the cat if it walks over my keyboard accidentally hitting the restart button?
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

14 Experts available now in Live!

Get 1:1 Help Now