Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving the User Name from the registry

Status
Not open for further replies.

tired22

Programmer
Nov 19, 2008
3
US
Is it possible to retrieve the user name for the current user from the registry? I'm not even sure where in the registry it can be found.
 
If you are on XP or Vista your current username is in an enviroment variable named USERNAME.
Start the command prompt and then enter
Code:
C:\>echo %username%
and you get the user name.

So you can retrieve that from this variable.
 
Okay, Thanks. But is there a way I can access that environment variable inside from inside a C++ program?

Also, is it possible to read data from a cookie file from inside a program? That's actually what I'm trying to do. The problem is that the cookie files are in Documents and Settins/<username>/.... and I can't determine the path without knowing the username. I actually tried just putting %username% as the name of the directory and it didn't work.

 
I just figured it out.

For anyone who may run into this in the future, I used the following include statement:

#include <cstdlib>

and used the following statement to retrieve the environment variable:


char* user = getenv("username");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top