How to get the Machine Name from a .NET Application using C# ?

You can use the MachineName property defined in the System.Environment class in order to get the Machine Name from your .NET Application.

How to get the Machine Name from a .NET Application using C# ?

Here’s a code sample demonstrating how to do it.

using System;

namespace ACConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Gets the Machine Name
            var machineName = Environment.MachineName;
            Console.WriteLine("The Machine Name is : " + machineName);
            Console.ReadLine();
        }
    }
}

This should display the machine name. The output of the program would be

The Machine Name is Abundantcode-LT

%d bloggers like this: