How to Execute a Program using Console Application in Csharp

This is a very simple and straight tutorial that aims to execute application program by typing the name of the program with a .exe file extension


Create a new project, select the Console Application, then click OK.


Go to Code Editor and type the code below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace ExecuteProgramInConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            String execApp;
            Console.Write("Type the application with an .exe extension: ");
            execApp = Console.ReadLine();
            try
            {
                Process.Start(execApp);
                Console.WriteLine("Application: " + execApp + " is running.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.Read();
        }
    }
}

Final Output:
How to Execute a Program using Console Application in Csharp How to Execute a Program using Console Application in Csharp Reviewed by code-dev on 10:04 PM Rating: 5

No comments:

Powered by Blogger.