473,320 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Avoid running multiple program instance ????

Dear all,

I have a vb.net application which start with a sub main procedure.
inside this sub main procedure I create a and instance from an assembly x like as follow:

sub main()
.....

Application.Run(New frmLogin)
end sub

frmLogin is a class inside assembly X

What I need to do, is to avoid launching 2 instances of my program. At the end my main startup programm which contains just the sub main is called NNS.exe wich instantiate a form object from X.dll

I have try many suggesting I get , like the findwindow, defining a mutex object, or simply checking the instance value but nothing goes.

Does anyone as a solution to avoid lunching multiple instance ??

regards
serge
Jul 21 '05 #1
3 2062
place this in the form load:

Dim aModuleName As String =
Diagnostics.Process.GetCurrentProcess.MainModule.M oduleName
Dim aProcName As String =
System.IO.Path.GetFileNameWithoutExtension(aModule Name)
If Process.GetProcessesByName(aProcName).Length > 1 Then
Me.Close()
Exit Sub
End If

-----Original Message-----
Dear all,

I have a vb.net application which start with a sub main procedure.inside this sub main procedure I create a and instance from an assembly x like as follow:
sub main()
.....

Application.Run(New frmLogin)
end sub

frmLogin is a class inside assembly X

What I need to do, is to avoid launching 2 instances of my program. At the end my main startup programm which
contains just the sub main is called NNS.exe wich
instantiate a form object from X.dll
I have try many suggesting I get , like the findwindow, defining a mutex object, or simply checking the instance
value but nothing goes.
Does anyone as a solution to avoid lunching multiple instance ??
regards
serge
.

Jul 21 '05 #2
Hmm...this indeed works. But what happens if i have the same EXE copied into a diff file name and invoke that?
This logic assumes that the original process's assembly and the current processe's assembly has the same name. I wonder what to do in that scenario.
--
Rakesh Rajan
"dave" wrote:
place this in the form load:

Dim aModuleName As String =
Diagnostics.Process.GetCurrentProcess.MainModule.M oduleName
Dim aProcName As String =
System.IO.Path.GetFileNameWithoutExtension(aModule Name)
If Process.GetProcessesByName(aProcName).Length > 1 Then
Me.Close()
Exit Sub
End If

-----Original Message-----
Dear all,

I have a vb.net application which start with a sub main

procedure.
inside this sub main procedure I create a and instance

from an assembly x like as follow:

sub main()
.....

Application.Run(New frmLogin)
end sub

frmLogin is a class inside assembly X

What I need to do, is to avoid launching 2 instances of

my program. At the end my main startup programm which
contains just the sub main is called NNS.exe wich
instantiate a form object from X.dll

I have try many suggesting I get , like the findwindow,

defining a mutex object, or simply checking the instance
value but nothing goes.

Does anyone as a solution to avoid lunching multiple

instance ??

regards
serge
.

Jul 21 '05 #3
With Deft Fingers, Rakesh Rajan <Ra*********@discussions.microsoft.com> wrote:
Hmm...this indeed works. But what happens if i have the same EXE copied into a diff file name and invoke that?
This logic assumes that the original process's assembly and the current processe's assembly has the same name. I wonder what to do in that scenario.


Try this...

' Check for Existing Running Application
Dim c As Process = Process.GetCurrentProcess()
Dim p As Process
For Each p In Process.GetProcessesByName(c.ProcessName)
If p.Id <> c.Id Then
msgPrompt = "This Program is already Running!"
msgTitle = "Program Opened"
MsgBox(msgPrompt, vbOKOnly, msgTitle)
' Close 2nd Application Event
Me.Close()
If p.MainModule.FileName = c.MainModule.FileName Then
End If
End If
Next p
Regards,

Bruce
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: PalB | last post by:
How to stop running multiple instances of my App in C#? Thanx
1
by: calderara serge | last post by:
Dear all, I have a VB.NET application which have no Windows form. it is just launched through the sub main procedure. How can I avoid launching multiple instance of my application ? I have...
6
by: AP | last post by:
Hello, I am having trouble trying to assign an object to a running program in windows in VB.NET A COM component class with the same name as the windows program is avaliable to use in VB.NET. The...
2
by: serge calderara | last post by:
Dear all, I have a vb.net application which start with a sub main procedure. inside this sub main procedure I create a and instance from an assembly x like as follow: sub main() ..... ...
2
by: SharpCoderMP | last post by:
i'm trying to embed multiple program icons in my executable. the only way so far i managed to do that is to embed native win32 resource file with multiple icons. it works, but... when i create a...
6
by: dspfun | last post by:
I would like to analyze my running c-program. What I would like to know for example is the range of the entire address space of my running c-program (memory reserved for/by the running program),...
1
by: Jim Langston | last post by:
Windows. Situation: Using a Python program called OpenRPG. I have a program that displays form data (a character sheet) in C++. I am able in the C++ program to build a string and copy it into the...
19
by: Zytan | last post by:
I want multiple instances of the same .exe to run and share the same data. I know they all can access the same file at the same time, no problem, but I'd like to have this data in RAM, which they...
0
Pakmarshal
by: Pakmarshal | last post by:
I am running a 3rd party application that runs in javaw.exe, when I try to launch the second instance of the application. The application doesn’t respond. If anyone can guide, is this javaw.exe...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.