Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve location of %UserProfile% programmatically in C++?

I'd like to find the directory of the current user profile programmatically in C++.

like image 593
Quincy Avatar asked May 03 '10 18:05

Quincy


2 Answers

SHGetSpecialFolderLocation is the best way to get at most of the special paths on Windows. Passed CSIDL_PROFILE it should retrieve the folder you are interested in.

If you are actually interested in the contents of the %UserProfile% environment variable you could try ExpandEnvironmentStrings

like image 104
Chris Becke Avatar answered Sep 28 '22 16:09

Chris Becke


Simplest way on Windows & Linux:

char *szBuff;
szBuff=std::getenv("USERPROFILE");  //Returning value of %USERPROFILE%
like image 37
Rupesh Shingavi Avatar answered Sep 28 '22 15:09

Rupesh Shingavi