I want to get the current computer name.
this is my code:
Public Function GetComputerName() As String
Dim ComputerName As String
ComputerName = System.Net.Dns.GetHostName
Return ComputerName
End Function
this code working, but i remember that there is faster way.
what is the fast way to get the computer name?
This is not that good the previous anwser,but if you love to work with forms:
System.Windows.Forms.SystemInformation gives a lot of nice informations.
-> UserDomainName
-> UserName
For WPF application:
Code Example #1
Code Example #2
Hope this gives you a more understanding on how to show the users Computer Name.
I stopped using Windows Form Applications because they are way to laggy. Now I'm using WPF Applications mainly because its a lot smoother and it has more customizations and coding WPF applications are a lot similar to Windows Form Applications.
you can just use without function:
or:
There is a nice static property that should work anywhere in your program and in both VB.NET and C#:
Because System namespace is imported automatically by default, it should be enough to refer to it simply by typing Environment.MachineName.
For unknown reason My.Computer.Name is not working for many people (including me) despite it is often being mentioned as a correct way to get the current hostname. So you don't need to bother trying to make it work.
An other way to get the computer name not mentioned in the previous responses:
Edit
Works for VB.NET only, not C#