The GetUserNameEx function with NameDisplay cannot work offline . This information is only available if the computer is online. I recommend that you implement some caching information, such as a full name or another, available only in online mode. For example, if the computer is online, you can retrieve and save information, such as Full username. Thus, you can have a mapping between the SID of users and its full name in your registry configuration file. If you cannot give the full name directly, you can get information from your money.
There are many different notifications on Windows (e.g. NotifyAddrChange ) that you can use (if necessary) to monitor changes online and offline.
Most of the information you can get about the current user session (also offline) can be obtained from the LsaGetLogonSessionData and WTSQuerySessionInformation API ( GetUserNameEx , which you already know), but you will not find the full username inside.
If you find a way to get your full username offline, write me this information.
source share