How to: Retrieve the Local Machine Name (C++/CLI)

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at How to: Retrieve the Local Machine Name (C++/CLI).

The following code example demonstrates the retrieval of the local machine name (the name of the computer as it appears on a network). You can accomplish this by getting the MachineName string, which is defined in the Environment namespace.

Example

// machine_name.cpp  
// compile with: /clr  
using namespace System;  
  
int main()   
{  
   Console::WriteLine("\nMachineName: {0}", Environment::MachineName);  
   return 0;  
}  

See Also

Windows Operations (C++/CLI)
.NET Programming with C++/CLI (Visual C++)