Click to See Complete Forum and Search --> : Check if an application is the same one from processID you got


DeafBug
September 28th, 2001, 11:31 AM
Hi,
I have done a search in this forum and I found everything I need. But one thing that I am concern about is the ProcessID. I am not too familiar with how they work. I know it is unique. I did a bunch of testing over time (without rebooting) and I did come across with the SAME processID used earlier. The question I have is "Is there a way to find out the name of the application based on the ProcessID?" I have not found an answer for it in this forum.

What I am doing is calling several external applications that we developed from the main program that we also developed. In other words one parent program and a number of child programs. Yes, we did code that the program can't be run from stand-alone and must be within the parent program (via command parameters) so it will always be launched from the parent program.

Now I have successfully added a bunch of API calls to launch and terminate the process (child program) within the parent program. Whenever a child is launch I save the ProcessID for that child. When the user wants to close the parent program, all child programs are killed first before parent unloads.

As I mentioned before that I did had a same ProcessID used twice. I want to know if there is a way to find out, the name of the external child program based on the ProcessID I had saved when it first launched. The reason I ask this is because I don't want to kill a process if it is not the child program of the parent. (If the user closed the child program and then opens Word which has the same processID that the child had.) I don't want to upset the users by closing a third-party program simply because the processID matched. I need a little more validation which would be the name of the application.

One thing, I should mention. All of our child programs can be running one instance. If they try to open a second instance, it brings up the first instance (code off from MS KB)

So I feel that it is foolproof that if I can match the ProcessID with the name of the program before terminating the process.

Any API calls I can use. Each one of them is individual and can be switched. Don't want to use the WaitForSingleObject or eat up CPU cycles. Just a simple check when the parent is unloading.

DeafBug
September 28th, 2001, 02:32 PM
Never mind. Since all the applications are written by us. We decided to put a registry key for each "child" application. When the child application gets launched, it will set the registry that it is open. When it gets unloaded, it will set the registry that it is closed.

The parent program will read the registry in the Form_QueryUnload and call TerminateProcess API for those that are still open (running) since it still is the same ProcessID assigned to it.


I have continued to look for code and time is running out. If you have code, please post.

softweng
September 28th, 2001, 03:12 PM
I am curious about the code you used to activate the first instance of you child
program if a second instance is started. I have done this before but
I would like to see how Microsoft recommends doing this.
Do you have a link to the KB article or can you post the code you used? Thanks!

Kris
Software Engineer
Phoenix,AZ

DeafBug
October 1st, 2001, 10:39 AM
Go to MS KB and the article is Q185730. Otherwise type Prevent Multiple Instance in the search field.

I tweaked the example provide by MS a bit.

softweng
October 1st, 2001, 10:52 AM
Thanks for the info!!!

Kris
Software Engineer
Phoenix,AZ