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

How do I pass a command line to another instance of my application which is already running

P: n/a

I have an application running. A file type is registered with this
application. When the user click on a file of such type a new instance
of the application is loaded with command line (file name).
I want to shut done this new instance an to notify the instance which
is already running, by passing the command line to it (so that the
file can be open by the application already runnning).

Here is my code, how do I notify the running instance ?
Partial Friend Class MyApplication

Private Sub MyApplication_Startup(ByVal sender As Object,
ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupE ventArgs)
Handles Me.Startup

G_CommandLine = e.CommandLine

Dim intAppInstances As Integer =
UBound(Diagnostics.Process.GetProcessesByName(Diag nostics.Process.GetCurrentProcess.ProcessName))
If intAppInstances 0 Then
MsgBox("Application already running")

' Here I want to notify the instance of the
application
'which is already running and pass to it the
CommandLine
' == how? ==

e.Cancel = True

End If

End Sub

End Class

Apr 10 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Pamela,

In VB 2005 you can select "Make single instance application" in the
application's Properties to create a single instance app.

When an attempt is made to start the app and it is already running, the
My.Application.StartupNextInstance event is raised. This event is provided a
StartupEventArgs object that contains the application's command-line
arguments.

Kerry Moorman
"pamela fluente" wrote:
>
I have an application running. A file type is registered with this
application. When the user click on a file of such type a new instance
of the application is loaded with command line (file name).
I want to shut done this new instance an to notify the instance which
is already running, by passing the command line to it (so that the
file can be open by the application already runnning).

Here is my code, how do I notify the running instance ?
Partial Friend Class MyApplication

Private Sub MyApplication_Startup(ByVal sender As Object,
ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupE ventArgs)
Handles Me.Startup

G_CommandLine = e.CommandLine

Dim intAppInstances As Integer =
UBound(Diagnostics.Process.GetProcessesByName(Diag nostics.Process.GetCurrentProcess.ProcessName))
If intAppInstances 0 Then
MsgBox("Application already running")

' Here I want to notify the instance of the
application
'which is already running and pass to it the
CommandLine
' == how? ==

e.Cancel = True

End If

End Sub

End Class

Apr 11 '07 #2

P: n/a
On 11 Apr, 14:22, Kerry Moorman
<KerryMoor...@discussions.microsoft.comwrote:
Pamela,

In VB 2005 you can select "Make single instance application" in the
application's Properties to create a single instance app.

When an attempt is made to start the app and it is already running, the
My.Application.StartupNextInstance event is raised. This event is provided a
StartupEventArgs object that contains the application's command-line
arguments.

Kerry Moorman

"pamela fluente" wrote:
I have an application running. A file type is registered with this
application. When the user click on a file of such type a new instance
of the application is loaded with command line (file name).
I want to shut done this new instance an to notify the instance which
is already running, by passing the command line to it (so that the
file can be open by the application already runnning).
Here is my code, how do I notify the running instance ?
Partial Friend Class MyApplication
Private Sub MyApplication_Startup(ByVal sender As Object,
ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupE ventArgs)
Handles Me.Startup
G_CommandLine = e.CommandLine
Dim intAppInstances As Integer =
UBound(Diagnostics.Process.GetProcessesByName(Diag nostics.Process.GetCurren*tProcess.ProcessName))
If intAppInstances 0 Then
MsgBox("Application already running")
' Here I want to notify the instance of the
application
'which is already running and pass to it the
CommandLine
' == how? ==
e.Cancel = True
End If
End Sub
End Class- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -
good idea: I will try that out. Thank you Kerry .

-P
Apr 11 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.