× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Running exe from command line with parameters

Codementor User
Feb 05, 2015
<p>In a WPF application, you can access the command line by using the static members of the Environment class...</p> <pre><code>public MainWindow() { var args = Environment.GetCommandLineArgs(); if (args.Length == 1) { MessageBox.Show("No argument provided"); Environment.Exit(0); } string arg1 = args[1]; // your argument InitializeComponent(); } </code></pre> <p>This snippet shows how to do it. Remember that the name of the assembly is always the first argument, so you are interested in args[1] and args[2] etc etc.</p> <p>The Environment class also has another member: Environment.CommandLine which has the entire command line as a string.</p> <p>For your second question, your syntax is fine.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/23071822/Running%20exe%20from%20command%20line%20with%20parameters/23072080">Stack Overflow</a>.</p>
comments powered by Disqus