-4

I was sitting around bored and thought of this idea. Is it possible to change the WM_DESTROY code so that it will do something else instead of closing the application. But, I don't think this will work, but does that keep it from closing when you try to close the application from the task manager in windows. Also, is there a way to remove my application from the task manager so they wouldn't be able to do that in the first place? So, is this possible or do you have a better way? I have googled this and have tried this, but I want to ask the experienced here to answer this question.

BTW, I am not making a virus.

nobody
  • 19,814
  • 17
  • 56
  • 77
cplusplus
  • 17
  • 4
  • 3
    No well behaved application would ever want to do what you are suggesting. You might not be writing a virus, but it doesn't make your request any more legitimate as far as good practices are concerned. – syam Sep 07 '13 at 22:26
  • @syam I was just wandering if it was possible. I really don't even have an idea of what I would use it for if I did want to use it. – cplusplus Sep 07 '13 at 22:28
  • @Whoever just upvoted the first comment - Read my above comment. – cplusplus Sep 07 '13 at 22:32
  • @Whoever just down voted my question - why did you do that and now up vote it – cplusplus Sep 07 '13 at 22:33
  • Yes it is possible. How? *If* I knew (and I'm not saying I do -- or don't) I certainly wouldn't tell you because I don't think it's ethical. I'm not saying **you** would make bad use of it, but since my answer would be public *someone else* could use it. Hope you understand. ;) – syam Sep 07 '13 at 22:33
  • @syam Almost the same thought I had: either a prank or a virus. – LorenzoDonati4Ukraine-OnStrike Sep 07 '13 at 22:34
  • @syan yeah, I understand, I guess I shouldn't have asked this. – cplusplus Sep 07 '13 at 22:35
  • NOBODY ANSWER SO OTHERS WON'T LEARN HOW TO DO THIS THAT WILL USE THIS ADVICE FOR SOMETHING THEY SHOULDN'T – cplusplus Sep 07 '13 at 22:36
  • come f*cking on guys, I asked a simple question and showed my research effort. If you down-voting because of the edit on there, then you shouldn't. I joined this forum again (I have had a previous account and had it deleted because of this same reason) so I could get help. But, you guys are down-voting my question so d*mn often that I can't ask questions. – cplusplus Sep 10 '13 at 15:15
  • Read the accepted answer to http://stackoverflow.com/questions/4655810/how-can-i-prevent-a-user-from-closing-my-c-sharp-application to understand why it's not possible. – Jim Mischel May 02 '14 at 18:17

2 Answers2

1

Windows Task Manager will use TerminateProcess to "close" a process - which is a good thing if your program has accidentally or on purpose got a broken VM_DESTROY handler.

There are supposedly ways to mess about with the process list that hides a process. But I don't actually know how that is done othat than very fundamentally (the process list is a linked list, and you can "unlink" a process from the list, and it "disappears"). Obviously doing so would be the type of thing that virus, trojan's, spyware, etc does, and I don't see any reason why you would want to do that in a legitimate application.

Edit: And hiding the application just means it doesn't appear in the list of processes in task manager. If you KNOW that the task exists (and you could for example "guess" based on system activity or some such), it can still be killed using it's process ID by some application that has enough privileges to terminate the process.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
  • I'd even call that a rootkit, but I'm just nitpicking on the terms. ;) +1 – syam Sep 07 '13 at 22:29
  • 1
    I really don't have a reason or am going to. I just wanted to know if it was possible. – cplusplus Sep 07 '13 at 22:30
  • 2
    @cplusplus Ok, I'll assume that you really have no bad intentions. I can understand the sheer pleasure of understanding how to break a system (that's what beta-testers like to do), but don't be surprised by the wary reactions you're getting. Asking such questions here is like asking a chemistry teacher what would happen when mixing nitric acid and glycerine, and where to get the two. – LorenzoDonati4Ukraine-OnStrike Sep 07 '13 at 22:44
  • @LorenzoDonati Yeah, I should have expected it. I never really gave that thought. – cplusplus Sep 07 '13 at 22:49
  • @LorenzoDonati Spot on. Whoever knows the answers to this question will never answer in public, for very different reasons. White hats don't want this information to spread because it is dangerous, and black hats don't want more competitors. Either way, no real answer will be given, only rebuffal. – syam Sep 07 '13 at 22:56
0

you shoud read win32 api demo. when mainwindow receives WM_DESTROY message, call postquitmessage([exitcode]) to end message loop。