Results 1 to 16 of 16

Thread: [RESOLVED] Run console app from a windows form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    27

    Resolved [RESOLVED] Run console app from a windows form

    Hey, I've made some console applications (two of them in my project) and then I decided to add a windows form into the project.

    Now I have placed two separate command buttons onto the form, but I'm confused about the code which must be written for the command buttons to launch the console applications on click.

    Normally, its something like:
    Code:
    Sub cmd_button1.Click()
    frmnew.Show
    frmthis.Hide
    End Sub
    What about loading the console application instead of another form? (The form and the console app's are all in the same project)

  2. #2
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Run console app from a windows form

    Using Shell command you can execute the console application
    Visual Studio.net 2010
    If this post is useful, rate it


  3. #3
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: Run console app from a windows form

    You can also use System.Diagnostics.Process.Start(path) and that will execute the app, or if it isn't an app, will open it in a suitable viewer.
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    27

    Re: Run console app from a windows form

    You can also use System.Diagnostics.Process.Start(path) and that will execute the app
    Well, that just simply switches back to the module in Visual Basic for the console application. I need it to load in the DOS window/command prompt (They are the same things right?)


    Using Shell command you can execute the console application
    Could you please provide the code, I've tried the shell command, but it never worked correctly.

  5. #5
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: Run console app from a windows form

    vb.net Code:
    1. Shell(path)

    As simple as that. The other parameters are optional.
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    27

    Re: Run console app from a windows form

    Code:
       1.
          Shell(path)
    Well, I did do that, I went into the console application, right clicked, and chose 'copy full path' then I pasted the path into the path parameter of the Shell command.
    Then when I ran the program in debug mode, it kept saying the object was not found.

  7. #7
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Run console app from a windows form

    is any error????
    u have to give the path in double quotes
    Visual Studio.net 2010
    If this post is useful, rate it


  8. #8
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Run console app from a windows form

    Quote Originally Posted by KrazyKomrade

    Could you please provide the code, I've tried the shell command, but it never worked correctly.
    why what error saying???
    Visual Studio.net 2010
    If this post is useful, rate it


  9. #9

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    27

    Re: Run console app from a windows form

    there really isn't any kind of error, it simply says "File not found"
    yes I did put the path in double quotes.
    Is there any other way to go from the windows form to the console application using something other than the Shell command?

  10. #10
    Junior Member
    Join Date
    Jul 2007
    Posts
    22

    Thumbs up Re: Run console app from a windows form

    Hi,
    Are you giving the exe path or the application class file path?
    You should give the executable file path.
    Except path all are optional params.

    Here is the syntax:
    shell(path_Name[,style][,wait][,timeout])
    path_name = executable file with the full path of the application
    Style = a model of application window(ex minimize,normal etc).
    Wait = a boolean value that prescriptive whether shell function has to wait vb.net finish before working. false is the default value.
    TimeOut = a wait time that it needful by shell function to start working if Wait in true value.

    Thanks.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    27

    Re: Run console app from a windows form

    Here's something that may help in solving this problem:

    All my files are location in one 'Solution' (.sln file) how can I switch between different objects (in this case from the windows form to the console application) using a command button?

    Please note I'm using Visual Basic 2008 Express Edition.

  12. #12
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: Run console app from a windows form

    Check that the file is indeed at that path, and if it is, then please post the path, there might be a problem with the path itself, although it's very unlikely.

    EDIT: I remember reading that Process.Start started VS. Are you sure that the file is an executable, and not some source file or something? Because using Shell implicitly says that the file you are trying to start is an executable of some kind. Please post the file name and extension so we can be sure.
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    27

    Re: Run console app from a windows form

    well, the console applications are named: 'server.vb' and 'client.vb'
    each is in: C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\fs_lan_mes\fs_lan_mes\File Here

    When I enter the code in the command button from the windows form (frm_main) I put this:

    Shell("C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\fs_lan_mes\fs_lan_mes\file I want")

    And I ignore all the other parameters.

  14. #14
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: Run console app from a windows form

    Quote Originally Posted by KrazyKomrade
    well, the console applications are named: 'server.vb' and 'client.vb'
    each is in: C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\fs_lan_mes\fs_lan_mes\File Here

    When I enter the code in the command button from the windows form (frm_main) I put this:

    Shell("C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\fs_lan_mes\fs_lan_mes\file I want")

    And I ignore all the other parameters.
    But the thing is, they ARE NOT EXECUTABLES! They are not applications! They are only the source code for an application! Hence the extension .vb, if they were applications, it would have been .exe or .com or .msi.

    The Shell method asks for an executable at the specified path, and since it doesn't find an executable, it says 'Object not found'. The Process.Start method opens the source file with the default editor - just what it's supposed to do. If you want the button to start an application built from that source file, link it to the .exe file in the /bin directory.
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    27

    Re: Run console app from a windows form

    But the thing is, they ARE NOT EXECUTABLES! They are not applications! They are only the source code for an application! Hence the extension .vb, if they were applications, it would have been .exe or .com or .msi.
    Wow...I'm an idiot
    Anyways, now I have to either find the executable files or make them myself.

  16. #16
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: Run console app from a windows form

    Quote Originally Posted by KrazyKomrade
    Wow...I'm an idiot
    Anyways, now I have to either find the executable files or make them myself.
    Well, just press the Build button, and then look in the /bin folder and the executable will be there.
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

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