How to: Retrieve the Current Username (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 Current Username (C++/CLI).

The following code example demonstrates the retrieval of the current user name (the name of the user logged into Windows). The name is stored in the UserName string, which is defined in the Environment namespace.

// username.cpp  
// compile with: /clr  
using namespace System;  
  
int main()   
{  
   Console::WriteLine("\nCurrent user: {0}", Environment::UserName);  
   return 0;  
}  

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

Show: