C# : Application Launcher (Console Application)



Application Launcher (Console Application)


Difficulty: 2 / 10
Assumed Knowledge: Basic methods and functions of Visual Basic.
Information: This tutorial teaches you the knowledge of launching application.


This little project allows you to luanch an application through your console.

Step 1: Setting the console up
To start this project, you will need to create a new visual C# console.

Posted Image

Step 2: Adding variables
Class:
namespace Launch_Sample__console_
{

       
class Program

       
{

               
static void Main()

               
{


               
}

       
}
}

Using statements:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

Step 3: Starting the main process
Starting the main part of the console.


                        String txtApp;


                       
Console.Write("Option: ");

                        txtApp
= Console.ReadLine();

Step 4: Try / Catch statement
                        try

                       
{

                               
Process.Start(txtApp);

                               
Console.WriteLine("Application: " + txtApp + ", Sucessfully Launched!");

                       
}

                       
catch (Exception ex)


                       
{

                 
             
Console.WriteLine(ex.Message);

                       
}


                       
Console.Read();


If the input the user types is correct, the application that matches the users input will run, But if the input the users type is incorrect, and does not match an application it will not run.

A Process component provides access to a process that is running on a computer. A process, in the simplest terms, is a running application. A thread is the basic unit to which the operating system allocates processor time. A thread can execute any part of the code of the process, including parts currently being executed by another thread.

Finished Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
// Jarryd Hoffman
namespace Launch_Sample__console_
{

       
class Program

       
{

               
static void Main()

               
{

                       
String txtApp;


                       
Console.Write("Option: ");

                        txtApp
= Console.ReadLine();


                       
try

                       
{

                               
Process.Start(txtApp);

                               
Console.WriteLine("Application: " + txtApp + ", Sucessfully Launched!");

                       
}

                       
catch (Exception ex)

                       
{

                               
Console.WriteLine(ex.Message);

                       
}


                       
Console.Read();

               
}

       
}
}

Success:
Posted Image

Fail:
Posted Image

No comments:

Post a Comment