Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CreateProcess confuses App.PrevInstance?

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
0
0
GB
I have an application which uses CreateProcess to start a separate smaller EXE which does some tasks and then terminates. I run it as a separate process so that if it hasn't finished after 30 seconds I can terminate it using TerminateProcess from within the main application.

A problem has arisen though; if a user closes the main application while the separate smaller EXE is running and then tries to restart the main application it won't run because the first few lines say "If App.PrevInstance = True Then End". I can confirm that no previous instance of the main application is running in task manager so I can only assume that for some reason VB thinks that the smaller EXE is in fact the same as the main EXE as far as PrevInstance is concerned.

Is there a way I can start the smaller EXE so that it doesn't interfere with App.PrevInstance?

- Andy
___________________________________________________________________
If a man speaks in a forest and there are no women around to hear him - will he still be wrong?
 
App.PrevInstance has numerous issues since it relies on an old 16-bit Windows mechansim that is not faithfully emulated in Win32 (32- and 64-bit Windows).

It sounds like one of these may be that all processes in a process family look like one "instance" to this property.

You can try using the CREATE_NEW_PROCESS_GROUP flag (dwFlags parameter of CreateProcess). Or you can try a more reliable way of detecting a pre-existing instance.

Some will suggest a Mutex object for this. I find the DDE mechanism works well enough if not better myself. Maybe read through thread222-1567400 ?
 
>I can only assume that for some reason VB thinks that the smaller EXE is in fact the same as the main EXE as far as PrevInstance is concerned.
Very strange for me. I have never seen App.PrevInstance fail in the way described above. Can you show the complete initialization code?

>Is there a way I can start the smaller EXE so that it doesn't interfere with App.PrevInstance?
Is there any specific reason you are using CreateProcess instead of the Shell function? In case you thought it will be required for tracking new process for using TerminateProcess function later, you can do the same with Shell function as well. CreateProcess is not necessary for that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top