Only Allow One Instance Of EXE When Shell

  • Thread starter Thread starter Derek Hart
  • Start date Start date
D

Derek Hart

I have a VB6 program that is going to Shell a VB.Net program to run. I want
the VB.Net program to only run once, so it if is not running and it is
Shelled, the program runs; if it is already running and it is Shelled, then
I wish the program to become visible. I do have to use the Shell process
since I do not have control over the VB6 program, other than what parameters
are sent to the Shell. Any ideas on how this can be accomplished?

Thank You,
Derek
 
Hello,

Derek Hart said:
I have a VB6 program that is going to Shell a VB.Net
program to run. I want the VB.Net program to only run
once, so it if is not running and it is Shelled, the program
runs; if it is already running and it is Shelled, then I
wish the program to become visible. I do have to
use the Shell process since I do not have control over the
VB6 program, other than what parameters are sent to the
Shell. Any ideas on how this can be accomplished?

In the VB.NET application:

\\\
Imports System.Threading
..
..
..
Dim m As Mutex = _
New Mutex(False, "{11C92606-65D9-4df2-9AEA-B6A4DA91BCE2}")
If m.WaitOne(10, False) Then
Application.Run(New Form1())
m.ReleaseMutex()
Else
MessageBox.Show("Application already running!")
End If
///

You can use 'AppActivate' to activate the other instance.

HTH,
Herfried K. Wagner
 
Got this from a previous posting:

Just add that piece of code (here in C#) in your main method (you need to
include the System.Diagnostic namespace) :
Process currentProcess = Process.GetCurrentProcess();

Process [] allProcesses =
Process.GetProcessesByName(currentProcess.ProcessName);


if (allProcesses.Length > 1)

{

MessageBox.Show(currentProcess.ProcessName + " is already running !",
currentProcess.ProcessName, MessageBoxButtons.OK, MessageBoxIcon.Error);

}

else

{

//do your stuff here

}
 
Back
Top