Refer to a specific instance of an application

Posted on 2006-05-01
Last Modified: 2010-05-01
Dear Experts,

i have 2 developed 2 different applications that interface to a host system. I can have both my applications running at the same time so i'll need to launch the interface to the host application twice as well.

Now i know both my applications to know which instance of the host applications it launched. How can this be done?

Please Help!
Question by:vbhargav80
    LVL 12

    Assisted Solution


    If App.PrevInstance Then
      'Do something...
    End If
    LVL 3

    Expert Comment


    Private Sub Form_Load
       If App.PrevInstance Then
         me.caption = me.caption & " (Instance 2)"
       End If
    end sub

    The only problem that will occur is if you launch a 3rd instance, it would also show up as "<AppCaption> (Instance 2)".

    To overcome that you would need to send a command line parameter when launching all of them and put this in form load:

    Private Sub Form_Load

    if command > "" then
       me.caption = me.caption & " (Instance " & command & ")"
    end if

    end sub

    Then from a command line/script/application you would launch them with their instance number:

    C:\FakeProgram.exe 1
    C:\FakeProgram.exe 2
    C:\FakeProgram.exe 3

    Both of these are workarounds to enumerating the computer processes at startup and generating an instance number based on the count of processes matching the application path + 1.  If you go this route you are looking at either WMI or API for a solution.


    Author Comment

    Sorry for replying back so late.

    I think i did ot make my question clear enough.

    I have 2 different applications. App A and App B. Both of these can run at the same time.

    When these applications start (A and B) they both launch another application C.

    So when A and B are both running there will be 2 instances of C. Both A and B need to get data from application C. But how can i determine which application C was launched by A or B?

    LVL 3

    Accepted Solution

    The example above would display the difference in the two apps in the title bar of AppC.

    This would be the code for AppC Main/Form_Load:

    if command > "" then
       me.caption = "AppC (Launched By: " & Command & ")"
    end if

    And then launch AppC from AppA/AppB with different command line paramaters:

    Shell "C:\AppC.exe ApplicationA"

    Shell "C:\AppC.exe ApplicationB"

    That make any sense?

    Author Comment

    Again sorry for getting back so late. I've been really busy. Thanks for all your help though

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now