How can I get the path to the current User's home directory?
Ex: In Windows, if the current user is "guest" I need "C:\Users\guest"
My application will run on most of the Windows versions (XP, Vista, Win 7).
Use the function SHGetFolderPath. This function is preferred over querying environment variables since the latter can be modified to point to a wrong location. The documentation contains an example, which I repeat here (slightly adjusted):
#include <Shlobj.h> // need to include definitions of constants
// .....
WCHAR path[MAX_PATH];
if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, path))) {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With