Microsoft KB Archive/302656

= How to obtain the NetBIOS and DNS computer names by using Visual Basic .NET or Visual Basic 2005 =

Article ID: 302656

Article Last Modified on 12/6/2006

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



This article was previously published under Q302656





For a Microsoft Visual C# .NET version of this article, see 303902.



For a Microsoft Visual Basic 6.0 version of this article, see 175472.

IN THIS TASK

 * Summary
 * Steps to Build the Sample



SUMMARY
This article demonstrates how to obtain the name of the computer on which your application is running. The sample code in this article demonstrates how to obtain both the NetBIOS (simple) name and the fully qualified Domain Name System (DNS) computer name.

back to the top

Steps to Build the Sample
 Start Visual Studio .NET or Visual Studio 2005. Under Project Types, click Visual Basic Projects. Under Templates, click Console Application.

Note In Visual Studio 2005, click Visual Basic under Other Languages. Under Templates, click Console Application. Double-click Module1.vb to open the code window.

NOTE: You can also right-click Module1.vb, and then click View Code to open the code window.  Add the following code to Sub Main: Dim result As String

'Retrieve the NetBIOS name. result = System.Environment.MachineName

'Display the results to the console window. Console.WriteLine(&quot;NetBIOS Name = {0}&quot;, result)

'Retrieve the DNS name. result = System.Net.Dns.GetHostByName(&quot;LocalHost&quot;).HostName

'Display the results to the console window. Console.WriteLine(&quot;DNS Name = {0}&quot;, result) Note In Visual Studio 2005, you can change the code &quot;System.Net.Dns.GetHostByName&quot; to &quot;System.Net.Dns.GetHostEntry&quot; in line 13. For more information, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/netframework/aa497286.aspx

 Press the CTRL+F5 key combination to build and run the application. The NetBIOS and DNS computer names appear in the console window.

NOTE: If you use the CTRL+F5 key combination to start the program, the console window remains open after the code has completed.</ol>

back to the top

Additional query words: environment

Keywords: kbvs2005applies kbvs2005swept kbhowtomaster kbprod2web KB302656

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.