Determine own file from being closed

just write whatever you want
Post Reply
Posts: 49
Joined: Mon Dec 14, 2009 6:29 am

Determine own file from being closed

Post by ira »

I am trying to prevent my program from being closed. So, I hooks TerminateProcess etc.

if myprogram then

What is the best way to check "myprogram" is really my program?
File name? :(
Hash?? It can make system slower if the file size is big..
Any idea?
Site Admin
Posts: 10539
Joined: Sun Mar 21, 2004 5:25 pm

Re: Determine own file from being closed

Post by madshi »

Why is this in "fun talk"?

Anyway, this is a difficult question to answer because there's a lot of information missing. My first suggestion would be this:

(1) In your application, before injecting the hook dll, create a global file mapping (see "CreateGlobalFileMapping") and write your process ID into it.
(2) In your hook dll's initialization, open the global file mapping.
(3) In your TerminateProcess etc callback, check if the target process has the same process ID as your own process.
Post Reply