SNIPPETBANK.NET FOLLOW US ON TWITTER

Set Computer Name

The code below sets the computer name. You need to restart your computer for the new computer name to take effect.

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace SetComputerName
{
    class Program
    {
        [DllImport("kernel32.dll")]
        static extern bool SetComputerName(string lpComputerName);

        static void Main(string[] args)
        {
            bool done = SetComputerName("MajorSoft");

            if (done)
            {
                Console.WriteLine("Done");
            }

            Console.ReadKey();
        }
    }
}

Videos