What about adding a function like this to the Platform stuff (or in a common place) ?

const String getCurrentUserName()
String userName;

userName = String(getenv(“USER”)).trim();

if (userName.isEmpty())
  char text[255];
  memset(text, 0, sizeof(text));

  FILE* whoami = popen("whoami", "r");
  char* retVal = fgets(text, sizeof(text), whoami);
  (void*) retVal;

  userName = String(text);

#elif JUCE_WIN32
wchar_t text[250];
::ExpandEnvironmentStrings(L"%userprofile%", text, sizeof(text));

  userName = String(text);

jassertfalse // Unknown platform ! cannot determine user

return userName.trim();



That’s quite a coincidence - I needed exactly the same thing for something I was writing yesterday, and you’ve saved me the trouble of looking up how to do it! Thanks, I’ll probably put it into the SystemStats class.


well, i’ve updated it cause on some win systems it make the use of wchar_t instead of char… don’t know if the fix works ok for most platforms there…


I think the JUCE_WIN32 is a bit too discriminatory here, cause it should fail on Win64.
I know under visual C++, _WINDOWS is defined all the time (for 32 and 64 bit programs), maybe you could use it ? (Don’t know if it’s defined by default on other IDEs though)


I’ve already implemented it properly and added it to the build, so don’t worry about the code in this thread.


cool thanx man :slight_smile: