GetComputerName (kernel32)
Last changed: dauth-202.166.147.204

.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern bool GetComputerName([Out] StringBuilder lpBuffer,
   ref uint lpnSize);

User-Defined Types:

None.

Notes:

The GetComputerName function retrieves the NetBIOS name of the local computer. This name is established at system startup, when the system reads it from the registry.

Tips & Tricks:

Please add some!

Sample Code:

    class Class1
    {
        [DllImport("kernel32", CharSet=CharSet.Unicode)]
        static extern bool GetComputerName(string name, ref int len);

        [STAThread]
        static void Main(string[] args)
        {
            String computerName="abcdefghijklmnopqrstuvwxyz";
    // this is wrong. You can not pass string to function GetComputerName, as result will be the same string. String object is immutable, so u can not not change it after cration. In order this code to work u have to use System.Text.StringBuilder object instead of string.
            int len = 100;
            GetComputerName(computerName, ref len);
            Console.WriteLine(computerName.Substring(0,len));
        }
    }

Alternative Managed API:

System.Environment.MachineName will get you the netbios name.

Documentation