Host Name or Computer Name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Who can I get hostname of local machine?

I have found following, but I am not sure all Windows OS(XP/2000/NT/98..) will have the "COMPUTERNAME" environment variable.

System.Environment.GetEnvironmentVariable("COMPUTERNAME");

Is there any better & more reliable way to get hostname/computer name of local machine, where my application are going to run?

Thanks,
Avin Patel
 
You should try the following:

System.Windows.Forms.SystemInformation.ComputerName


Lajos Malozsák

Avin Patel said:
Hi,
Who can I get hostname of local machine?

I have found following, but I am not sure all Windows OS(XP/2000/NT/98..)
will have the "COMPUTERNAME" environment variable.
System.Environment.GetEnvironmentVariable("COMPUTERNAME");

Is there any better & more reliable way to get hostname/computer name of
local machine, where my application are going to run?
 
Try this.

string myHostName = System.Net.Dns.GetHostName();

or

string myHostName = Environment.MachineName;

Shak.



Avin Patel said:
Hi,
Who can I get hostname of local machine?

I have found following, but I am not sure all Windows OS(XP/2000/NT/98..)
will have the "COMPUTERNAME" environment variable.
System.Environment.GetEnvironmentVariable("COMPUTERNAME");

Is there any better & more reliable way to get hostname/computer name of
local machine, where my application are going to run?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top