place this in the form load:
Dim aModuleName As String =
Diagnostics.Process.GetCurrentProcess.MainModule.ModuleName
Dim aProcName As String =
System.IO.Path.GetFileNameWithoutExtension(aModuleName)
If Process.GetProcessesByName(aProcName).Length > 1 Then
Me.Close()
Exit Sub
End If
[quoted text, click to view] >-----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
[quoted text, click to view] >
>I have try many suggesting I get , like the findwindow,
defining a mutex object, or simply checking the instance
value but nothing goes.
[quoted text, click to view] >
>Does anyone as a solution to avoid lunching multiple
instance ??
>
>regards
>serge
>.
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
[quoted text, click to view] "dave" wrote:
> place this in the form load:
>
> Dim aModuleName As String =
> Diagnostics.Process.GetCurrentProcess.MainModule.ModuleName
> Dim aProcName As String =
> System.IO.Path.GetFileNameWithoutExtension(aModuleName)
> 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
> >.
> >
[quoted text, click to view] With Deft Fingers, Rakesh Rajan <RakeshRajan@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,
Don't see what you're looking for? Try a search.