Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Host Name or Computer Name

189 views
Skip to first unread message

Avin Patel

unread,
Jun 15, 2004, 10:33:02 AM6/15/04
to
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

Lajos Malozsak

unread,
Jun 15, 2004, 11:19:37 AM6/15/04
to
You should try the following:

System.Windows.Forms.SystemInformation.ComputerName


Lajos Malozsák

"Avin Patel" <Avin...@discussions.microsoft.com> wrote in message
news:4B978C82-FF24-4F72...@microsoft.com...

Shakir Hussain

unread,
Jun 15, 2004, 11:27:51 AM6/15/04
to
Try this.

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

or

string myHostName = Environment.MachineName;

Shak.

"Avin Patel" <Avin...@discussions.microsoft.com> wrote in message
news:4B978C82-FF24-4F72...@microsoft.com...

Avin Patel

unread,
Jun 16, 2004, 10:36:03 AM6/16/04
to
HI,

> string myHostName = System.Net.Dns.GetHostName();
>
Documentation says: It would return DNS host name, NOT machine name / computer name / host name.

> or
>
> string myHostName = Environment.MachineName;
>

"Environment.MachineName" not found in documentation. But I tried & it works.
Is this a magic?? How can be it guranted to work in user application??

Thanks,
Avin Patel


Avin Patel

unread,
Jun 16, 2004, 10:40:23 AM6/16/04
to
HI,
How come I don't see "System.Windows.Forms.SystemInformation.ComputerName" in C# CRL API, But still it compiles & works ok?

Thanks,
Avin Patel

Avin Patel

unread,
Jun 16, 2004, 11:10:24 AM6/16/04
to
HI,
I have found it, I was looking at different API downloaded from web.

Thanks,
Avin Patel

Avin Patel

unread,
Jun 16, 2004, 11:10:27 AM6/16/04
to
HI,
I have found it, I was looking at different API downloaded from web.

Thanks,
Avin Patel

0 new messages