By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,870 Members | 2,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,870 IT Pros & Developers. It's quick & easy.

Only Allow One Instance Of EXE When Shell

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello,

"Derek Hart" <dm****@gte.net> schrieb:
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
--
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Jul 19 '05 #2

P: n/a
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.ProcessN ame);
if (allProcesses.Length > 1)

{

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

}

else

{

//do your stuff here

}

"Derek Hart" <dm****@gte.net> wrote in message
news:eL**************@tk2msftngp13.phx.gbl...
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

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.