There is such a batch file:

cd "D:\Program Files (x86)\xxxx\xxx\" "D:\Program Files (x86)\xxxx\xxx\xx\3\3.exe" -"D:\Program Files (x86)\xxxx\xxx\Questions\2_2.png" pause 

It runs my 3.exe program and must pass a parameter to it .

 "D:\Program Files (x86)\xxxx\xxx\Questions\2_2.png" 

The question is, how can I get this parameter in the WindowsForms application? For example, in the variable string fp;

    1 answer 1

    http://ideone.com/ORYEby

     static int Main(string[] args) { var fp = args[0]; 

    This is for the console application as I understand it, but for WindowsForms?

    The WinForms application has a Program.cs file with the Main function.


    And yet, the arguments can be obtained in another way:

     string[] args = Environment.GetCommandLineArgs(); string fp = args[1]; // Тут в args[0] имя программы. 

    Swears at one (What am I doing wrong?

    1. Probably run without parameters.
      The number of arguments passed should be checked.
    2. In VS, in the properties settings of a project, you can configure the launch with parameters.
    • 2
      In .NET, argv [0] is skipped and in args [0] there will be the first command line parameter? - Vladimir Martyanov
    • one
      @ Vladimir Martianov, yes. args are the parameters. To get to the bottom of the call method, you need to climb in Environment.CommandLine and parse your hands. - Qwertiy
    • Oh, they are inventors ... - Vladimir Martyanov
    • @ Vladimir Martianov , ideone.com/ORYEby - Qwertiy
    • one
      In fact, not “the name of the executable program file”, but “an arbitrary string controlled by the calling process”. - VladD