Mirror

Get computer name and user (Views: 100)


Problem/Question/Abstract:

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;

<< Back to main page