Click on the Start button. Right-click on Computer. Select Properties. Under Computer name, domain, and workgroup settings you will find the computer name listed.
In the window the window that appears on the bottom-left hand corner of your screen, type in cmd and click OK. The command prompt window will appear. In this window, type hostname and press Enter. The name of your computer will be displayed.
Look up Your Computer's Domain Name. For Windows machines, click on the Start Menu, go to Control Panel, System and Security, then System. You'll see your computer's domain name at the bottom.
System.Environment.MachineName
from a console or WinForms app.HttpContext.Current.Server.MachineName
from a web appSystem.Net.Dns.GetHostName()
to get the FQDNSee How to find FQDN of local machine in C#/.NET ? if the last doesn't give you the FQDN and you need it.
See details about Difference between SystemInformation.ComputerName, Environment.MachineName, and Net.Dns.GetHostName
System.Environment.MachineName
Or, if you are using Winforms, you can use System.Windows.Forms.SystemInformation.ComputerName
, which returns exactly the same value as System.Environment.MachineName
.
System.Environment.MachineName
Some methods are given below to get machine name or computer name
Method 1:-
string MachineName1 = Environment.MachineName;
Method 2:-
string MachineName2 = System.Net.Dns.GetHostName();
Method 3:-
string MachineName3 = Request.ServerVariables["REMOTE_HOST"].ToString();
Method 4:-
string MachineName4 = System.Environment.GetEnvironmentVariable("COMPUTERNAME");
For more see my blog
string name = System.Environment.MachineName;
Well there is one more way: Windows Management Instrumentation
using System.Management;
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT Name FROM Win32_ComputerSystem");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_ComputerSystem instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Name: {0}", queryObj["Name"]);
}
}
catch (ManagementException e)
{
// exception handling
}
MSDN
WMI
WMI Code creator
FAQs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With