Mega Code Archive

 
Categories / Delphi / System
 

How to get computer name and user logged on

Title: How to get computer name and user logged on. Question: This article presents a code snipet which shows how to get the current user and the computer name. Answer: Obviously this is not a complete program, but you can use the Windows API calls GetUserName and GetComputerName as shown below. uses windows ... var u: array[0..127] of Char; c: array[0..127] of Char; user: string; computer: string; sz: dword; begin sz := SizeOf(u); GetUserName(u, sz); sz := SizeOf(c); GetComputerName(c, sz); user := u; computer := c; end;