Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 Get the Command Line Arguments

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET-keretrendszer 3.5

Other versions are also available for the following:
Windows Presentation Foundation
How to: Get the Command Line Arguments

This example shows how to get the command line arguments that were passed to an application.

The following code demonstrates how to use Application and the Startup event to get the command line arguments.

<Application
    x:Class="CSharp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Startup="app_Startup"
    >
</Application>

C#
using System;
using System.Windows;

namespace CSharp
{
    public partial class App : Application
    {
        void app_Startup(object sender, StartupEventArgs e)
        {
            // If no command line arguments were provided, don't process them
            if (e.Args.Length == 0) return;

            // Get command line arguments
            foreach (string argument in e.Args)
            {
                switch (argument)
                {
                    case "arg1":
                        // Process arg 1
                        break;
                    case "arg2":
                        // Process arg 2
                        break;
                    case "arg3":
                        // Process arg 3
                        break;
                }
            }
        }
    }
}

For an example of retrieving and using command line arguments, see Processing Command Line Arguments Sample.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker