Recent

Author Topic: [SOLVED] How to get User's Full Name  (Read 6681 times)

lazguy

  • Jr. Member
  • **
  • Posts: 78
[SOLVED] How to get User's Full Name
« on: November 28, 2017, 07:01:18 pm »
Hello Everybody,

I need to get the User's Full Name of the current logged user, not the Username.

Not the result of SysUtils.GetEnvironmentVariable('USERNAME')


Thank you very much in advance
« Last Edit: November 28, 2017, 11:13:45 pm by lazguy »

balazsszekely

  • Guest
Re: How to get User's Full Name
« Reply #1 on: November 28, 2017, 07:34:19 pm »
GetUserNameEx( https://msdn.microsoft.com/en-us/library/windows/desktop/ms724435(v=vs.85).aspx )? You can find the declaration in unit JwaWindows.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: How to get User's Full Name
« Reply #2 on: November 28, 2017, 09:59:00 pm »
I use GetUserNameEx() as well.

If that fails, or is unavailable, I fallback to WMI instead.  I use GetUserName() and LookupAccountName() to get domain and username, and then query the FullName from the Win32_UserAccount table.

Also look at NetGetUserInfo() with level=10 (other levels also have a full name as well).
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

lazguy

  • Jr. Member
  • **
  • Posts: 78
[SOLVED] How to get User's Full Name
« Reply #3 on: November 28, 2017, 11:06:46 pm »
GetUserNameEx( https://msdn.microsoft.com/en-us/library/windows/desktop/ms724435(v=vs.85).aspx )? You can find the declaration in unit JwaWindows.

Thank you very much GetMem. It worked !

lazguy

  • Jr. Member
  • **
  • Posts: 78
[SOLVED] How to get User's Full Name
« Reply #4 on: November 28, 2017, 11:08:52 pm »
I use GetUserNameEx() as well.

If that fails, or is unavailable, I fallback to WMI instead.  I use GetUserName() and LookupAccountName() to get domain and username, and then query the FullName from the Win32_UserAccount table.

Also look at NetGetUserInfo() with level=10 (other levels also have a full name as well).

Thank you very much, Remy Lebeau. I used GetMem solution

lazguy

  • Jr. Member
  • **
  • Posts: 78
[SOLVED] How to get User's Full Name
« Reply #5 on: November 29, 2017, 02:20:56 pm »
Code: Pascal  [Select][+][-]
  1. function TForm1.GetUserNameExString(ANameFormat: DWORD): string;
  2. const
  3.   NameUnknown = 0; // Unknown name type.
  4.   NameFullyQualifiedDN = 1; // Fully qualified distinguished name
  5.   NameSamCompatible = 2; // Windows NT® 4.0 account name
  6.   NameDisplay = 3; // A "friendly" display name
  7.   NameUniqueId = 6; // GUID string that the IIDFromString function returns
  8.   NameCanonical = 7; // Complete canonical name
  9.   NameUserPrincipal = 8; // User principal name
  10.   NameCanonicalEx = 9;
  11.   NameServicePrincipal = 10; // Generalized service principal name
  12.   DNSDomainName = 11; // DNS domain name, plus the user name
  13. var
  14.   Buf: array[0..256] of Char;
  15.   BufSize: DWORD;
  16. begin
  17.   Result := '';
  18.   BufSize := SizeOf(Buf) div SizeOf(Buf[0]);
  19.   if JwaWindows.GetUserNameEx(ANameFormat, @Buf[0], BufSize) then
  20.     Result := Buf;
  21. end;
  22.  

 

TinyPortal © 2005-2018