   FLAMING DEATH: TerminateProcess not work!
  It's possible for a process to not be terminated by TerminateProcess() right?  How can I close the process if that won't work?  Is there maybe some forceful asm code?  How can I make my programs un-terminateable?  Thanks for your help!   Kings of Chaos[edited by - n0ob on July 31, 2003 12:45:15 AM]
  A bit of RTFM tells me this:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/terminateprocess.aspquote:Original post by MSDN   The handle must have the PROCESS_TERMINATE access right. For more information, see Process Security and Access Rights. You must set the process to have access rights to terminate the process. However, remember that using TerminateProcess might mess up global state information inside DLL, I suggest you use ExitProcess instead.Toolmaker-Earth is 98% full. Please delete anybody you can.    [edited by - toolmaker on August 1, 2003 4:11:30 AM];  I''m opening the handle with PROCESS_ALL_ACCESS already, which supposedly includes the PROCESS_TERMINATE flag.  I''m wanting to terminate a different process than my own.. wouldn''t I have to use TerminateProcess() for that?  Doesn''t ExitProcess() end the current process?  Thanks for at least posting anyway..   Kings of Chaos;quote:Original post by n0ob  I''m opening the handle with PROCESS_ALL_ACCESS already, which supposedly includes the PROCESS_TERMINATE flag.  I''m wanting to terminate a different process than my own.. wouldn''t I have to use TerminateProcess() for that?  Doesn''t ExitProcess() end the current process?  Thanks for at least posting anyway..   Kings of Chaos Not a Win expert, but:If you''re opening a different process, I think it might have it''s own permissions, and that opening a handle to it with PROCESS_ALL_ACCESS flag set only means that''s what you want, not what you''ll get?Just a thought, don''t give it much weight, as I''m a *nix programmer after all...;  Are you seeking to terminate some other process or prevent your process from being terminated? I can understand why you might want to terminate some other process, but preventing your process from being terminated is rather bad behavior for a program. The ubiquitous question is: Are you trying to write a virus of some kind? Using TerminateProcess to kill another process is messy. It doesn''t give the target process the opportunity to unload dlls, free memory and perform other shutdown chores. It''s more work on your part, but  it''s possible to inject code into another process and then have that code call ExitProcess. To prevent TerminateProcess from killing your process, you would have to hijack that function and then cross check the handle argument against the handle to your process. Take note that the handle returned by GetCurrentProcess is a pseudo-handle. It''s value is always -1, iirc. You could probably find all the pieces of code necessary to do this by googling for vx sites and the like. But if you want to learn about what it takes to do all that, get yourself a copy of "Programming Applications" (Richter) and "Inside Windows 2000" (Russinovich) - for starters. Pietrek''s "Under the Hood" column at MSDN is also a good place to start. ;  okay, thanks.. I guess I''ll have to research code injection now   Thanks though, I see its probably too much for me right now.   Kings of Chaos;  okay okay I give up, i just can''t take it anymore!  Could you please tell me the basic idea behind ''code injection'' as you call it, and keywords to research!!  Thanks!   Kings of Chaos;  TerminateProcess will work provided that:1) you have the necessary privileges to open a suitable handle to the process2) the process is not currently inside the kernel due to a syscallIf the first condition isn''t met, the attempt to terminate will simply fail.If the latter condition isn''t met, the process won''t be terminated until execution returns to user mode.In order to obtain a suitable handle to the process you may (if it''s running under a different user context) need to enable SeDebugPrivilege.;  To prevent TerminateProcess from killing your process it will take more than DLL injection; it will take patching every running program or perhaps instead the kernel.And if I really wanted to terminate your process I could; I could, for instance, start a thread in your process and from it call ExitProcess; I could scribble over your memory causing you to execute an illegal instruction and cause the OS to terminate you; and I can do various other things, like freeze all your threads, close all your handles, and unload all your libraries.;  when I tried to use it I used terminateProcess() first, then if that failed, used WriteProcessMemory to write crap in the processe''s memory.  But neither worked, and I was thinking that the Write/ReadProcessMemory functions weren''t working on the special process.Kings of Chaos