How do I get the computer name in .NET c#
+10
A:
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.
Zach Johnson
2009-11-20 03:41:56
+2
A:
tvanfosson says true and his answer is good but our work is done by one.. you not need more answer .. in programming we can do everything by various method. but we need only one method for solve our problem
I always use System.Environment.MachineName for get the computer name in .NET
+26
A:
System.Environment.MachineNameHttpContext.Current.Server.MachineNameSystem.Net.Dns.GetHostName()(if you need the fully qualified name)
tvanfosson
2009-11-20 03:46:57
@tvanfosson: what is the difference ? I mean, which one should I use when? Does this have any security implications?
P.K
2009-11-20 04:26:22
I would use the first from a console or winforms app, the second from a web app, and the third if I needed to get the FQDN. See the referenced documentation for information on the permissions required.
tvanfosson
2009-11-20 11:49:53
+1
A:
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
}
PRR
2009-11-20 04:54:00
+2
A:
http://stackoverflow.com/questions/1072431/get-a-full-computer-name-or-domain-in-c
System.Environment.MachineName
Adam
2009-11-24 10:46:16