473,396 Members | 2,013 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,396 software developers and data experts.

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


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
2 4198
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Casey | last post by:
Yeah, I know this question was asked by someone elselike 2 weeks ago. But I need some additional help. I have a program I'm developing, and multiple different forms will be opened. For now though,...
21
by: Colleyville Alan | last post by:
I am now using the Execute command to run SQL for action queries. When I had them as saved queries, I would use DoCmd.SetWarnings False to allow the queries to overwrite existing tables. when I...
2
by: Adam Clauss | last post by:
I am building a GUI to wrap around some of the information/abilities contained within the program netsh. I have figured out how to use redirect the standardinput and standardoutput so that I can...
5
by: Adam Nowotny | last post by:
I want my application to be able to load most components it uses at user logon (f.e. by running "prog.exe /startup") and create a NotifyIcon to show up in tray. Now when i load the prog.exe second...
12
by: BartlebyScrivener | last post by:
I'm still new at this. I can't get this to work as a script. If I just manually insert the values for sys.argv and sys.argv it works fine, but I can't pass the variables from the command line. What...
3
by: Richard | last post by:
Hi All, I'm running MySQL version: 5.0.15-nt on WinXP-Pro/SP2. I created a one-line batch file DumpPAM.bat in a directory on the PATH: mysqldump pmtallocmodel_development %1%.txt I...
51
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under...
1
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.