Author: Dennis Passmore How to get the name and domain of a logged-in user Answer: In the form's OnClose method, call AnimateWindow. For example, the following call fades out the window: 1 2 function NetServerGetInfo(serverName: PWideChar; level: Integer; 3 var bufptr: Pointer): Cardinal; stdcall; external 'NETAPI32.DLL'; 4 5 function NetApiBufferFree(buffer: Pointer): Cardinal; stdcall; external 6 'NETAPI32.DLL'; 7 8 type 9 SERVER_INFO_503 = record 10 sv503_sessopens: Integer; 11 sv503_sessvcs: Integer; 12 sv503_opensearch: Integer; 13 sv503_sizreqbuf: Integer; 14 sv503_initworkitems: Integer; 15 sv503_maxworkitems: Integer; 16 sv503_rawworkitems: Integer; 17 sv503_irpstacksize: Integer; 18 sv503_maxrawbuflen: Integer; 19 sv503_sessusers: Integer; 20 sv503_sessconns: Integer; 21 sv503_maxpagedmemoryusage: Integer; 22 sv503_maxnonpagedmemoryusage: Integer; 23 sv503_enablesoftcompat: BOOL; 24 sv503_enableforcedlogoff: BOOL; 25 sv503_timesource: BOOL; 26 sv503_acceptdownlevelapis: BOOL; 27 sv503_lmannounce: BOOL; 28 sv503_domain: PWideChar; 29 sv503_maxcopyreadlen: Integer; 30 sv503_maxcopywritelen: Integer; 31 sv503_minkeepsearch: Integer; 32 sv503_maxkeepsearch: Integer; 33 sv503_minkeepcomplsearch: Integer; 34 sv503_maxkeepcomplsearch: Integer; 35 sv503_threadcountadd: Integer; 36 sv503_numblockthreads: Integer; 37 sv503_scavtimeout: Integer; 38 sv503_minrcvqueue: Integer; 39 sv503_minfreeworkitems: Integer; 40 sv503_xactmemsize: Integer; 41 sv503_threadpriority: Integer; 42 sv503_maxmpxct: Integer; 43 sv503_oplockbreakwait: Integer; 44 sv503_oplockbreakresponsewait: Integer; 45 sv503_enableoplocks: BOOL; 46 sv503_enableoplockforceclose: BOOL; 47 sv503_enablefcbopens: BOOL; 48 sv503_enableraw: BOOL; 49 sv503_enablesharednetdrives: BOOL; 50 sv503_minfreeconnections: Integer; 51 sv503_maxfreeconnections: Integer; 52 end; 53 PSERVER_INFO_503 = ^SERVER_INFO_503; 54 55 function Get_User_Name: string; 56 var 57 dwlen: DWORD; 58 begin 59 dwlen := MAX_COMPUTERNAME_LENGTH + 1; 60 Setlength(Result, dwlen); 61 GetUserName(pchar(Result), dwlen); 62 Result := StrPas(pchar(Result)); 63 end; 64 65 function Get_Computer_Name: string; 66 var 67 dwlen: DWORD; 68 begin 69 dwlen := MAX_COMPUTERNAME_LENGTH + 1; 70 Setlength(Result, dwlen); 71 GetComputerName(pchar(Result), dwlen); 72 Result := StrPas(pchar(Result)); 73 end; 74 75 function GetDomainName: string; 76 var 77 err: Integer; 78 buf: pointer; 79 fDomainName: string; 80 wServerName: WideString; 81 begin 82 wServerName := Get_Computer_Name; 83 err := NetServerGetInfo(PWideChar(wServerName), 503, buf); 84 if err = 0 then 85 try 86 fDomainName := PSERVER_INFO_503(buf)^.sv503_domain; 87 finally 88 NetAPIBufferFree(buf) 89 end; 90 Result := fDomainName; 91 end;