Author: Tomas Rutkauskas How to retrieve the computer name Answer: Solve 1: 1 function ComputerName: string; 2 var 3 size: DWORD; 4 begin 5 size := MAX_COMPUTERNAME_LENGTH + 1; 6 SetLength(Result, size - 1); 7 if not GetComputerName(PChar(Result), size) then 8 Result := ''; 9 end; Solve 2: 10 uses 11 Windows; 12 13 procedure GetPCName(var PCName: string); 14 var 15 nSize: DWORD; 16 begin 17 nSize := MAX_COMPUTERNAME_LENGTH + 1; 18 PCName := ''; 19 SetLength(PCName, nSize); 20 if GetComputerName(PChar(PCName), nSize) then 21 SetLength(PCName, nSize); 22 end; Solve 3: 23 function GetLocalComputerName: string; 24 var 25 iLen: cardinal; 26 begin 27 iLen := 255; 28 SetLength(Result, iLen + 1); 29 if (GetComputerName(PChar(Result), iLen) = false) then 30 begin 31 RaiseLastWin32Error; 32 end; 33 SetLength(Result, iLen); 34 end;