none
How t osend a parameter to a VS2017 exe RRS feed

  • Question

  • I have a windows form project in VS2017 that runs a report. I want to be able to run the run the program (exe) from a batch file and send a parameter from the batch file to the program and have the program retrieve that parameter and do something based on it. How do I accomplish this (both the format of sending the parameter in the batch and how to code the vs2017 project to get that information). I found some info about the command line arguments under debug but that sounds like sending parameters from the program, not to.

    Thanks

    Thursday, December 14, 2017 3:39 PM

All replies

  • Hi J-Bal,

    >>I found some info about the command line arguments under debug but that sounds like sending parameters from the program, not to.

    According to your description, you want to run the program (exe) from a batch file and send a parameter from the batch file to the program and have the program retrieve that parameter and do something based on it.

    As far as I know, you could run the program(exe) via a batch file, the following code for your reference, but winform app is client application, which could not receive the parameter from external.

    start "windowTitle" fullPath/file.exe

    I would suggest that you could write the parameter into a text file, then winform application read the parameter from text when it launch. For more information about write parameter into txt file, please refer to:

    https://stackoverflow.com/questions/1115508/batch-find-and-edit-lines-in-txt-file

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 15, 2017 6:16 AM
  • >I have a windows form project in VS2017 that runs a report. I want to be able to run the run the program (exe) from a batch file and send a parameter from the batch file to the program and have the program retrieve that parameter and do something based on it. How do I accomplish this (both the format of sending the parameter in the batch and how to code the vs2017 project to get that information).

    Your WinForm project will have a Main entry point like this (in C#):

            static void Main( string[] args )

    ... where it can obtain any command line parameters passed to it.

    From there you could pass the parameters to your (modified) main form constructor.

    You're of course limited to passing things on the command line as strings rather than anything more structured.

    Dave

    Friday, December 15, 2017 9:13 AM