Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6799043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:48:05+00:00 2026-05-26T18:48:05+00:00

Salve! I want to exit my GUI application (vb.net 4) using a commandline parameter.

  • 0

Salve! I want to exit my GUI application (vb.net 4) using a commandline parameter. I should send this from the commandline:

myapplication.exe quit

-and an already running instance of the application should exit.
Now, I have a mutex detection in place so that I can only have one instance of the application running at a time. It seems that if I send a commandline, it won’t work on an already running application; it will only work on one that is launching.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:48:06+00:00Added an answer on May 26, 2026 at 6:48 pm

    Easy Send Message to Running Instance of Application

    Hello, everyone! After finding this nice post here, looking for a way that a single application would do one thing with the first instance, but the second instance would cause the first instance do something else.

    The value of this is that you can (with your own, additional programming) use this to achieve the effect of sending commandline parameters to a running application. You would actually use a second instance of the app to send the commandline parameters as messages to the first instance. It works okay on my Windows XP, but I’m rather new to vb.net, so if you’ve any improvements, I’d like to know!

    So I adapted anoriginalidea’s nice example and below is my result. This is the bare-bones of it all, so you just see here the essentials of the process.

    It works like this:

    1. First, stick this here module in your application.
    2. Then launch app1
    3. you will get a message saying, “InterCom Server Reporting for Duty!”
    4. now launch app2 – you will get a message (it is actually from app1!), saying “My name is
      really Bob!” to let you know that the function fired off.
    5. then app2 will exit (you told it to in sub main) and
      then app1 will exit becuase app2 told it to exit when InterComClient()
      was called.

    first add this as your sub main
    the mutex will check to see if your application is already running or not.

    Public Sub Main()
        Dim createdNew As Boolean = True
        Using mutex As New Mutex(True, "TestForKalatorMutexProcess", createdNew)
            If createdNew Then
                InterComServer()
                'BE SURE TO CHANGE myApplication TO YOUR PRIMARY FORM!
                Application.Run(new myApplication)
            Else
                InterComClient()
                application.exit()
            End If
        End Using
    End Sub
    

    Now Add this in a module in your application

    Imports System.Runtime.Remoting
    Imports System.Runtime.Remoting.Channels
    Imports System.Runtime.Remoting.Channels.ipc 'You have to add this as a reference!
    
    Public Module intercom
    #Region "-------------InterShared-------------------------------------"
    Public Interface ICommunicationService
        Sub SaySomething(ByVal text As String)
    End Interface
    #End Region
    
    #Region "-------------InterComClient-------------------------------------"
    'This will run on the second instance
    Public Sub InterComClient(ByRef intercommessage As String)
        Try
            Dim ipcCh As New IpcChannel("myClient")
            ChannelServices.RegisterChannel(ipcCh, False)
            Dim obj As ICommunicationService = DirectCast(Activator.GetObject(GetType(ICommunicationService), "ipc://IPChannelName/SreeniRemoteObj"), ICommunicationService)
            obj.SaySomething(intercommessage)
            Thread.Sleep(1000)
            ChannelServices.UnregisterChannel(ipcCh)
        Catch ex As Exception
            'If you use this as a way to exit your application, be sure to discard this exception
            'because the InterCom Server won't be running to receive the closing of the channel
            'and it will throw a "Pipe Ended" error that can't be solved.
            'To "discard" the error, simply catch it and don't do anything.
            'Dim errmsg As New Messenger("Exception in InterComClient" & vbCr & ex.Message)
        End Try
    End Sub
    #End Region
    
    #Region "-------------InterComServer-------------------------------------"
    Public Class CommunicationService
        Inherits MarshalByRefObject
        Implements ICommunicationService
        Public Sub SaySomething(ByVal whatmessage As String) Implements ICommunicationService.SaySomething
            msgbox("InterCom Client Heard this : " & whatmessage)
            Application.exit
        End Sub
    End Class
    
    Public Sub InterComServer()
        Dim ipcCh As IpcChannel
        ipcCh = New IpcChannel("IPChannelName")
        ChannelServices.RegisterChannel(ipcCh, False)
        RemotingConfiguration.RegisterWellKnownServiceType(GetType(CommunicationService), "SreeniRemoteObj", WellKnownObjectMode.Singleton)
        MsgBox("InterCom Server Reporting for Duty!")
    End Sub
    #End Region
    
    End Module
    

    [update]

    Just FYI for anyone, I’ve used this in my application now for awhile, and it seems to work very well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When reading/writing a file in my application, I want to exit(1) if the file
I want to upload my application to iTunes Connect using application loader. For that
I am developing one application. In that application I want to put Exit button.
I want to save the value of a string at exit of my application(process
So I have this very simply SDL application I want to be able to
I want to save and load my xml data using XmlReader. But I don't
i am trying to make a java application with GUI. i am writing a
1) I want to save case 1 value to an array. Return this array
I have a Perl script that outputs text. I want to import this text
I have two set of arrays in different MYSQL table. This what I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.