As suggested by Brian Roach in the comments, it's pretty easy to do this with JNA, as it has a built-in shell for Secur32 that wraps the GetUsernameEx () function (which ultimately is a system call wrapped in the .NET library you linked above).
Usage will be something like this:
import com.sun.jna.ptr.IntByReference; import com.sun.jna.platform.win32.Secur32; // ... char[] name = new char[100]; // or whatever is appropriate Secur32.INSTANCE.GetUserNameEx( Secur32.EXTENDED_NAME_FORMAT.NameDisplay, name, new IntByReference(name.length) ); String fullName = new String(name).trim();
Note that this will give you the full name in the same format as typing net user %USERNAME% /domain
on the command line.
source share