GetComputerName (kernel32)
Last changed: dauth-202.166.147.204

.
Summary

C# Signature:

[DllImport("kernel32", CharSet=CharSet.Unicode)]
static extern bool GetComputerName(string lpBuffer, ref int 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:

There is a .net class for this.

Sample Code:

Here is the PINVOKE way, but I think just using the BCL System.Environment.MachineName is alot easier. It also requires alot less code.

    class Class1
    {
        [DllImport("kernel32.dll")]
        public static extern bool GetComputerName
            (StringBuilder lpBuffer,
            ref int nSize);
        [STAThread]
        static void Main(string[] args)
        {
            StringBuilder b=new StringBuilder(100);
            int n=b.Capacity;
            bool rc=GetComputerName(b, ref n);
            Console.WriteLine(b);
        }
    }

Alternative Managed API:

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

Documentation