C# - Set Computer Name

Sets a new NetBIOS name for the local computer. You need to restart your computer for the new computer name to take effect. You must also have administrative privileges.

Program

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4. using System.Runtime.InteropServices;  
  5.  
  6. namespace SetComputerName  
  7. {  
  8.     class Program  
  9.     {  
  10.         [DllImport("kernel32.dll")]  
  11.         static extern bool SetComputerName(string lpComputerName);  
  12.  
  13.         static void Main(string[] args)  
  14.         {  
  15.             bool done = SetComputerName("NEW_NAME");  
  16.  
  17.             if (done)  
  18.             {  
  19.                 Console.WriteLine("Done");  
  20.             }  
  21.  
  22.             Console.ReadKey();  
  23.         }  
  24.     }  
  25. } 

1 comment:

verakot said...

Does not work in Windows 10 [Version 10.0.18362.959]

Post a Comment