How to get logged-in user\'s full name (the one he/she entered as his/her real name) using windows API or something else? For example how to get \"John Smith\", not \"john\"
I believe I have found a related answer which works better than GetUserNameEx alone, that is to say, I can handle some cases where GetUserNameEx fails.
My alternative answer is here including sample code for Delphi.
In short, if GetUserInfoEx(3,...) fails, read GetUserInfoEx(2,...) which returns a name in the form "machinename\username", which you can then pass into NetUserInfo functions in NETAPI32.dll, which will read the local SAM database, which is where the user's full name is stored, if they have set it in the local SAM database. Of course, many home non-domain users have never set this up, so the other answers here are likely to provide some hints too.