Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2094
  • Last Modified:

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

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
i7mad
Asked:
i7mad
  • 8
  • 7
  • 4
  • +3
1 Solution
 
ThievingSixCommented:
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
 
JohnBusiness Consultant (Owner)Commented:
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
 
i7madAuthor Commented:

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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
JohnBusiness Consultant (Owner)Commented:
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
 
i7madAuthor Commented:
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
 
JohnBusiness Consultant (Owner)Commented:
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
 
moorhouselondonCommented:
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
 
Geert GOracle dbaCommented:
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
 
i7madAuthor Commented:

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
 
moorhouselondonCommented:
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
 
Geert GOracle dbaCommented:
>> 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
 
i7madAuthor Commented:

Geert_Gruwez:

 BDE, Paradox tables.
0
 
i7madAuthor Commented:

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
 
moorhouselondonCommented:
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
 
Geert GOracle dbaCommented:
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
 
abelCommented:
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
 
abelCommented:
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
 
Geert GOracle dbaCommented:
@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
 
i7madAuthor Commented:
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
 
Geert GOracle dbaCommented:
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
 
i7madAuthor Commented:
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
 
Geert GOracle dbaCommented:
sounds like my wife :)
0
 
abelCommented:
> 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
 
Geert GOracle dbaCommented:
these systems are mostly plc systems
they use EEPROMS ... totally different
0
 
Geert GOracle dbaCommented:
i would advice a good whipping, that allways helps as a reminder to "stay off !"
0
 
abelCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 8
  • 7
  • 4
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now