command line arguments for a windows app

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CLEAR-RCIC

    command line arguments for a windows app

    I want to write a windows app that accepts command line arguments. Does
    anyone know if this can be done and if so, how to do it.
  • Dave

    #2
    Re: command line arguments for a windows app

    Executing a console app:

    ConsoleApp.exe -switch2

    with the following class produces this output:

    Switch two activated.

    Class definition:

    public class ConsoleApp
    {
    static void Main(string[] args)
    {
    if (args != null && args.Length > 0)
    {
    switch (args[0].Trim().ToLower ())
    {
    case "-switch1":
    Console.WriteLi ne("Switch one activated.");
    break;
    case "-switch2":
    Console.WriteLi ne("Switch two activated.");
    break;
    default:
    Console.WriteLi ne("No options selected");
    break;
    }
    }
    else
    Console.WriteLi ne("No options selected");
    }
    }


    --
    Dave Sexton
    dave@www..jwaon line..com
    -----------------------------------------------------------------------
    "CLEAR-RCIC" <CLEARRCIC@disc ussions.microso ft.com> wrote in message news:9AB5EB9A-8442-49C6-B255-3F7F3D084D88@mi crosoft.com...[color=blue]
    >I want to write a windows app that accepts command line arguments. Does
    > anyone know if this can be done and if so, how to do it.[/color]


    Comment

    • CLEAR-RCIC

      #3
      Re: command line arguments for a windows app

      Will this work for a Windows Form App?

      "Dave" wrote:
      [color=blue]
      > Executing a console app:
      >
      > ConsoleApp.exe -switch2
      >
      > with the following class produces this output:
      >
      > Switch two activated.
      >
      > Class definition:
      >
      > public class ConsoleApp
      > {
      > static void Main(string[] args)
      > {
      > if (args != null && args.Length > 0)
      > {
      > switch (args[0].Trim().ToLower ())
      > {
      > case "-switch1":
      > Console.WriteLi ne("Switch one activated.");
      > break;
      > case "-switch2":
      > Console.WriteLi ne("Switch two activated.");
      > break;
      > default:
      > Console.WriteLi ne("No options selected");
      > break;
      > }
      > }
      > else
      > Console.WriteLi ne("No options selected");
      > }
      > }
      >
      >
      > --
      > Dave Sexton
      > dave@www..jwaon line..com
      > -----------------------------------------------------------------------
      > "CLEAR-RCIC" <CLEARRCIC@disc ussions.microso ft.com> wrote in message news:9AB5EB9A-8442-49C6-B255-3F7F3D084D88@mi crosoft.com...[color=green]
      > >I want to write a windows app that accepts command line arguments. Does
      > > anyone know if this can be done and if so, how to do it.[/color]
      >
      >
      >[/color]

      Comment

      • Daniel O'Connell [C# MVP]

        #4
        Re: command line arguments for a windows app


        "CLEAR-RCIC" <CLEARRCIC@disc ussions.microso ft.com> wrote in message
        news:FDB3035C-E828-4D91-8AD0-F4A83E558D08@mi crosoft.com...[color=blue]
        > Will this work for a Windows Form App?
        >[/color]

        It should.



        Comment

        • CLEAR-RCIC

          #5
          Re: command line arguments for a windows app

          I'm not sure I understand. Winform projects don't have a Main(). Then have
          a Form_Load with already take a certain number of parameters. It doesn't
          allow you to overload it with more parameters.


          "Daniel O'Connell [C# MVP]" wrote:
          [color=blue]
          >
          > "CLEAR-RCIC" <CLEARRCIC@disc ussions.microso ft.com> wrote in message
          > news:FDB3035C-E828-4D91-8AD0-F4A83E558D08@mi crosoft.com...[color=green]
          > > Will this work for a Windows Form App?
          > >[/color]
          >
          > It should.
          >
          >
          >
          >[/color]

          Comment

          • Daniel O'Connell [C# MVP]

            #6
            Re: command line arguments for a windows app


            "CLEAR-RCIC" <CLEARRCIC@disc ussions.microso ft.com> wrote in message
            news:76BCB36F-1F40-46E7-85F5-2F7C823AC9DD@mi crosoft.com...[color=blue]
            > I'm not sure I understand. Winform projects don't have a Main(). Then
            > have
            > a Form_Load with already take a certain number of parameters. It doesn't
            > allow you to overload it with more parameters.
            >[/color]

            They most assuredly do have a Main(). Most of the time it will be calling
            Application.Run on your form.

            Are you using VB by chance? If you are, you might have to ask someone who
            knows the langauge better as I believe the default setup generates the Main
            for you instead of having it in code explicitly.
            [color=blue]
            >
            > "Daniel O'Connell [C# MVP]" wrote:
            >[color=green]
            >>
            >> "CLEAR-RCIC" <CLEARRCIC@disc ussions.microso ft.com> wrote in message
            >> news:FDB3035C-E828-4D91-8AD0-F4A83E558D08@mi crosoft.com...[color=darkred]
            >> > Will this work for a Windows Form App?
            >> >[/color]
            >>
            >> It should.
            >>
            >>
            >>
            >>[/color][/color]


            Comment

            • CLEAR-RCIC

              #7
              Re: command line arguments for a windows app

              OK. I got it working. Thanks for the help!!!

              "Daniel O'Connell [C# MVP]" wrote:
              [color=blue]
              >
              > "CLEAR-RCIC" <CLEARRCIC@disc ussions.microso ft.com> wrote in message
              > news:76BCB36F-1F40-46E7-85F5-2F7C823AC9DD@mi crosoft.com...[color=green]
              > > I'm not sure I understand. Winform projects don't have a Main(). Then
              > > have
              > > a Form_Load with already take a certain number of parameters. It doesn't
              > > allow you to overload it with more parameters.
              > >[/color]
              >
              > They most assuredly do have a Main(). Most of the time it will be calling
              > Application.Run on your form.
              >
              > Are you using VB by chance? If you are, you might have to ask someone who
              > knows the langauge better as I believe the default setup generates the Main
              > for you instead of having it in code explicitly.
              >[color=green]
              > >
              > > "Daniel O'Connell [C# MVP]" wrote:
              > >[color=darkred]
              > >>
              > >> "CLEAR-RCIC" <CLEARRCIC@disc ussions.microso ft.com> wrote in message
              > >> news:FDB3035C-E828-4D91-8AD0-F4A83E558D08@mi crosoft.com...
              > >> > Will this work for a Windows Form App?
              > >> >
              > >>
              > >> It should.
              > >>
              > >>
              > >>
              > >>[/color][/color]
              >
              >
              >[/color]

              Comment

              Working...