Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
How to: Retrieve the Current Username

How to: Retrieve the Current Username 

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.

Example

// username.cpp
// compile with: /clr
using namespace System;

int main() 
{
   Console::WriteLine("\nCurrent user: {0}", Environment::UserName);
   return 0;
}

See Also

Community Additions

ADD
Show:
© 2015 Microsoft