4

I want to create exe file in that I want to pass parameters in C#.net

for eg: myexe.exe "hello"

pls help

Subodh
  • 79
  • 1
  • 1
  • 2
  • 3
    And what is your question? In a console application, you can access the parameters in your `Main` method using the `args` parameter. – Daniel Hilgarth Aug 23 '11 at 07:14
  • Check out http://msdn.microsoft.com/en-us/library/acy3edy3.aspx – Cosmin Pârvulescu Aug 23 '11 at 07:18
  • 3
    On Google, I found your [exact same question][1], which is already answered on Code Project. It was right there, between all the others answers I got when I googled for the title of your post. [1]: http://www.codeproject.com/Questions/244255/How-I-create-exe-in-that-I-pass-parameters-in-Csha – GolezTrol Aug 23 '11 at 07:18

3 Answers3

13

Use command arguments for this :

  static void Main(string[] args)
    {
        if (args.Length > 0)
        {
            Console.WriteLine("You Provided " + args[0]);
        }

    }

and now you can execute myexe.exe "hello" and it will print

You Provided hello

Gaurav
  • 840
  • 4
  • 16
6

to make your app receive parameters

static void Main(string [] args)
            {         
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // the args is the arguments you want to pass to this application
                Application.Run();

            }

to call it from a c# application

static void CallProcess(string[] args)
        {
            // create a new process
            Process pro= new Process();

            pro.StartInfo.FileName   = "exe path";
            pro.StartInfo.Arguments = args;

            pro.Start();
        }
Quantum
  • 23
  • 7
Sara S.
  • 1,365
  • 1
  • 15
  • 33
5

Main() method has arguments which will hold your "hello":

static int Main(string[] args) 
{
     System.Console.WriteLine(args[0]); //this will output "hello", when you call yourApp.exe "hello"
}
Renatas M.
  • 11,694
  • 1
  • 43
  • 62