Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. WinForm launching a console application

WinForm launching a console application

Scheduled Pinned Locked Moved C#
csharpquestion
13 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Pass a mystery parm to the console app that only the Windows Form knows about. No parm, no run.

    It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

    D Offline
    D Offline
    Dave Kreskowiak
    wrote on last edited by
    #4

    You can easily get the command line parameter from Task Manager, so the passed value should be changed every time it needs to be launched. I was thinking the parameter could be randomized or something else, then verified over a named pipe, or other IPC, with the WinForms app.

    Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
    Dave Kreskowiak

    L 1 Reply Last reply
    0
    • P picasso2

      I have a C# console application that is launched from a WinForm application.
      The output of the console application is well-formatted; however, user can run the console application directly. Is there a way to restrict/force the console application to be only run from the main application (WinForm)?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #5

      Just to add to what the others have said, If it's never to be run by the user, why create a console app at all? Why not just run it as a separate thread within the existing WinForms process?

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      T 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Just to add to what the others have said, If it's never to be run by the user, why create a console app at all? Why not just run it as a separate thread within the existing WinForms process?

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        T Offline
        T Offline
        trønderen
        wrote on last edited by
        #6

        May I suggest a possible answer? The shell actually performs some quite useful tasks. If you make extensive use of shell facilities, it may take quite a few code lines to duplicate the functionality in your WinForms code.

        OriginalGriffO 1 Reply Last reply
        0
        • T trønderen

          May I suggest a possible answer? The shell actually performs some quite useful tasks. If you make extensive use of shell facilities, it may take quite a few code lines to duplicate the functionality in your WinForms code.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #7

          Attaching a Console to a WinForms application[^] :-D

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            You can easily get the command line parameter from Task Manager, so the passed value should be changed every time it needs to be launched. I was thinking the parameter could be randomized or something else, then verified over a named pipe, or other IPC, with the WinForms app.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #8

            I was counting on the "user" being "typical" ... Task Manager? Wazzat? This looked like an "inhouse" solution ... Anybody trying to bypass this simple solution is obviously asking for trouble.

            It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

            D 1 Reply Last reply
            0
            • L Lost User

              I was counting on the "user" being "typical" ... Task Manager? Wazzat? This looked like an "inhouse" solution ... Anybody trying to bypass this simple solution is obviously asking for trouble.

              It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #9

              The thing about your "typcial" user is that some of them stumble across how to do things they shouldn't normally know how to do. NEVER assume users stay uninformed. Security is only secure in an environment that never changes or is touched from the outside, and that's never the case.

              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
              Dave Kreskowiak

              L 1 Reply Last reply
              0
              • D Dave Kreskowiak

                The thing about your "typcial" user is that some of them stumble across how to do things they shouldn't normally know how to do. NEVER assume users stay uninformed. Security is only secure in an environment that never changes or is touched from the outside, and that's never the case.

                Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                Dave Kreskowiak

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #10

                There's a difference between "accidently" running a console app versus defeating a method intended to prevent "accidents". Yes, there is a chance someone will type: ConsoleApp.exe supercalifragilisticexpialidocious. There is also such a thing as overkill based on what the console app actually does.

                It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                D 1 Reply Last reply
                0
                • L Lost User

                  There's a difference between "accidently" running a console app versus defeating a method intended to prevent "accidents". Yes, there is a chance someone will type: ConsoleApp.exe supercalifragilisticexpialidocious. There is also such a thing as overkill based on what the console app actually does.

                  It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #11

                  Oh I get it, I've been here before. I speak from experience I cannot talk about.

                  Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                  Dave Kreskowiak

                  L 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    Oh I get it, I've been here before. I speak from experience I cannot talk about.

                    Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                    Dave Kreskowiak

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #12

                    One size does not fit all.

                    It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                    1 Reply Last reply
                    0
                    • P picasso2

                      I have a C# console application that is launched from a WinForm application.
                      The output of the console application is well-formatted; however, user can run the console application directly. Is there a way to restrict/force the console application to be only run from the main application (WinForm)?

                      T Offline
                      T Offline
                      TimWallace
                      wrote on last edited by
                      #13

                      As OriginalGriff suggested, you should probably just run it as a thread in the process. But if you insist launching a console app, have your WinForms app create shared memory that your console app will look for when launched. If not found, terminate the console app.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups