How to obtain the NetBIOS and DNS computer names by using Visual Basic .NET or Visual Basic 2005 (302656)
The information in this article applies to:
- Microsoft Visual Basic 2005
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
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 TASKSUMMARY 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("NetBIOS Name = {0}", result)
'Retrieve the DNS name.
result = System.Net.Dns.GetHostByName("LocalHost").HostName
'Display the results to the console window.
Console.WriteLine("DNS Name = {0}", result)
Note In Visual Studio 2005, you can change the code "System.Net.Dns.GetHostByName" to "System.Net.Dns.GetHostEntry" in line 13. For more information, visit the following Microsoft Web site: - 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.
back to the top
Modification Type: | Major | Last Reviewed: | 10/9/2006 |
---|
Keywords: | kbvs2005applies kbvs2005swept kbHOWTOmaster kbProd2Web KB302656 kbAudDeveloper |
---|
|