Mega Code Archive

 
Categories / Delphi / Examples
 

Getusername

If you are connected to a LAN try this in stead - its also more secure. function GetNetUserName: string; var pcUser: PChar; dwUSize: DWORD; begin dwUSize := 21; // user name can be up to 20 characters GetMem(pcUser, dwUSize); // allocate memory for the string try if NO_ERROR = WNetGetUser(0, pcUser, dwUSize) then Result := pcUser; finally FreeMem(pcUser); end; end;