Results 1 to 17 of 17

Thread: Possible to start seperate exe specific form?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Possible to start seperate exe specific form?

    This may sound silly but is it possible to run a separate exe and call a specific form to load?

    For example:

    Let's say I have two exes one that checks licensing and then once that is done it calls another separate exe to load a specific form based on the type of license selected?

    It sounds doable but can anyone share a snip it of code that may do the trick?

    Is this possible?

    -Chris

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Possible to start seperate exe specific form?

    Sure, you can call/run another .Exe.
    As for loading a specific form in this other .Exe, this needs to be handled in this other .Exe. You can use CommandLine arguments to handover data to that .Exe.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: Possible to start seperate exe specific form?

    Thanks opus!

    I can call the 2nd exe fine it is just that I can't figure out how to get a specific form opened with it. Is there sample code you can point me to that I may look over and see if I can make this work?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Possible to start seperate exe specific form?

    This is one situation where I would say that it may be advisable to disable the Application Framework in your project and create your own Main method. That would be the case if you want this selected form to be the main form for your application. If you will actually always be using the same main form and these different forms are just a precursor to the main form then I would say not. If you can answer that question then we can provide the best advice.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: Possible to start seperate exe specific form?

    Hey Jmcilhinney,

    The main form IS the licensing app. The 2nd executable would be loaded upon successful license verification and depending on what version selected I would like it to load a specific form.

    I thought it would be as simple as calling the 2nd app and passing an argument to it to load a specific form.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Possible to start seperate exe specific form?

    Quote Originally Posted by cmmorris1 View Post
    The main form IS the licensing app.
    No it isn't.
    Quote Originally Posted by cmmorris1 View Post
    The 2nd executable would be loaded upon successful license verification and depending on what version selected I would like it to load a specific form.

    I thought it would be as simple as calling the 2nd app and passing an argument to it to load a specific form.
    You have two separate applications. Each application has its own main form. The second application doesn;t know anything about the first. It is completely independent and has its own main form. Is that main form going to be the same every time or is it going to be the form that you show based on the commandline used to start it?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: Possible to start seperate exe specific form?

    Oh, I see what you're saying. Sorry about that. It's been a long night

    Yes, you are correct and the 2nd application will show a specific form based on the command line used to start it...correct!

  8. #8
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Possible to start seperate exe specific form?

    As for the start of a second .exe:
    Code:
        Sub WhatEver(LicenseInfo as Integer)
             Dim p As New ProcessStartInfo
            ' Specify the location of the second .exe
            p.FileName = "C:\second.exe"
            Select Case LicenseInfo
                 Case 1
                      p.Arguments = "Type 1"
                CaseElse
                      p.Arguments = "Type 0"
            End Select
            ' Start the process
            Process.Start(p)
        End Sub
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: Possible to start seperate exe specific form?

    This is what I had originally which isn't working

    Code:
    Dim startInfo As New ProcessStartInfo
            startInfo.FileName = "myprogram.EXE"
            startInfo.Arguments = (Form1.p)
            Process.Start(startInfo)

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Possible to start seperate exe specific form?

    In that case, what I said before about disabling the Application Framework would be the way to go. Open the Application page of the project properties and uncheck the Application Framework box. The Startup Form field will then become Startup Object and you can select Sub Main.

    Next, add a module to your project named Program.vb with a Main method something like this:
    vb.net Code:
    1. Module Program
    2.  
    3.     <STAThread()> Sub Main(ByVal args As String())
    4.         Application.EnableVisualStyles()
    5.         Application.SetCompatibleTextRenderingDefault(False)
    6.  
    7.         Select Case args.Length
    8.             Case 0
    9.                 'No form specified.  Either show default or error.
    10.             Case 1
    11.                 Dim mainForm As Form
    12.  
    13.                 Select Case args(0)
    14.                     Case "Form1"
    15.                         mainForm = New Form1
    16.                     Case "Form2"
    17.                         mainForm = New Form2
    18.                     Case "Form3"
    19.                         mainForm = New Form3
    20.                     Case Else
    21.                         'Invalid form name.  Either show default or error.
    22.                 End Select
    23.  
    24.                 'Start the app with the appropriate main form.
    25.                 Application.Run(mainForm)
    26.             Case Else
    27.                 'Too many arguments.  Either ignore from second or error.
    28.         End Select
    29.  
    30.         MessageBox.Show("Hello World")
    31.     End Sub
    32.  
    33. End Module
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Possible to start seperate exe specific form?

    Quote Originally Posted by cmmorris1 View Post
    This is what I had originally which isn't working

    Code:
    Dim startInfo As New ProcessStartInfo
            startInfo.FileName = "myprogram.EXE"
            startInfo.Arguments = (Form1.p)
            Process.Start(startInfo)
    You can't actually pass a form from one app to the other. Commandline arguments are just strings. The first app needs to pass some string that the second app will recognise and act upon accordingly. The strings can be anything at all, as long as both apps understand what they mean. I would suggest either meaningful words that describe the form to show and/or its purpose, or else just simple numbers that have no specific meaning other than that agreed to by the two apps.

    One way to keep the two consistent would be to put the values into a simple DLL and have both apps reference that, or you can just rely on doing it manually and not making a mistake.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: Possible to start seperate exe specific form?

    Thanks guys for the tips. I will keep this open in case anyone has any other suggestions and to allow time to see what works best for me.

    If the 2nd app knows what form1.p is then won't the code I used work?

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Possible to start seperate exe specific form?

    Quote Originally Posted by cmmorris1 View Post
    If the 2nd app knows what form1.p is then won't the code I used work?
    What is Form1.p and how is the second app using it?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: Possible to start seperate exe specific form?

    This is how it's handled right now in the 2nd exe

    Code:
    Private Shared Sub Main()
                MySql.Connect
                If Not LicensingEvents.CheckUserLicensing Then
                    Dim mainForm As New FrmActivation
                    Application.Run(mainForm)
                Else
                    Form1.p = New Form1
                    Application.Run(Form1.p)
                End If
            End Sub

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Possible to start seperate exe specific form?

    Like I said, your second application doesn't know anything about the first. You aren't using commandline arguments at all there, so the second app is completely ignoring the information passed by the first app. The second app doesn't implicitly know about any information that the first app contained. The ONLY thing that the second app knows is what text was passed to it on the commandline, which you are ignoring. It doesn't even know where that text came from.

    I have shown you how to get the commandline argument(s): use the 'args' parameter in the Main method. You now need to implement something similar. The value of Form1.p in the first app is passed as a string to the second app and you get that string as an array of commandline arguments. That is all you have to work with.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: Possible to start seperate exe specific form?

    Thanks jmcilhinney!

  17. #17
    Junior Member
    Join Date
    Dec 2010
    Posts
    28

    Re: Possible to start seperate exe specific form?

    How does the second program get the args sent to it, in the case where your first program is the most useful and the 2nd program is used temporarily (a.k.a. not using a main() )?


    1st pgm:
    p.arguments = "4"

    2nd pgm's load should have a ???? stmt to say, "Ah, yes a received a "4" in the args list.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width