C++/CLI Code Snippet - Get local computer host name

C++/CLI Code Snippet - Get local computer host name

C++/CLI Code Snippet - Get local computer host name

C++/CLI code snippet get the host name from the local machine.

Bookmark:

C++/CLI Code Snippet - Get local computer host name

This .Net C++/CLI code snippet get the host name from the local machine. This function uses System.Net namespace to get local machine hostname. Modify the exception handling section to meet your project requirements.

/// <summary>
/// Gets host name of the local computer
/// </summary>
System::String ^GetLocalHostName()
{
    return System::Net::Dns::GetHostName();
}


Here is a simple example showing how to use above function (GetLocalHostName) to display local machine host name.

Console::WriteLine("Local computer host name : " + GetLocalHostName());


C++/CLI Keywords Used:

  • DNS
  • GetHostName
  • Exception

Code Snippet Information:

  • Applies To: Visual Studio, .Net, C++, CLI, DNS, Domain Name System, GetHostName
  • Programming Language : C++/CLI

External Resources:

Leave a comment