System info

Get all system languages

Posted in System info

You should use GetSystemLayoutList function to get identifiers of all system languages and use VerLanguagename function to convert these IDs to locales.

procedure TForm1.Button1Click(Sender: TObject);
var
  Count, i: Integer;
  MyLang: PChar;
  Layouts: array [0..16] of Integer;
const
  Size: Integer = 250;
begin
  GetMem(MyLang, Size);
  Count:=GetKeyboardLayoutList(16, Layouts);
  Memo1.Lines.Clear;
  for i:=0 to Count-1 do
  begin
    VerLanguageName(Layouts[i], MyLang, Size);
    Memo1.Lines.Add(StrPas(MyLang));
  end;
  FreeMem(MyLang);
end;

Get all environment variables

Posted in System info

To get a full list of environment variables, use GetEnvironmentStrings function. But it is necessary to process result.

procedure TForm1.Button1Click(Sender: TObject);
var
  Variable: Boolean;
  Str: PChar;
  Res: string;
begin
  Str:=GetEnvironmentStrings;
  Res:='';
  Variable:=False;
  while True do begin
    if Str^=#0 then
    begin
      if Variable then Memo1.Lines.Add(Res);
      Variable:=True;
      Inc(Str);
      Res:='';
      if Str^=#0 then
        Break
      else
        Res:=Res+str^;
    end
    else
      if Variable then Res:=Res+Str^;
    Inc(str);
  end;
end;

Get a user name

Posted in System info

Use GetUserName for solving of this problem. For example:

procedure TForm1.Button1Click(Sender: TObject);
var
  StrUserName: PChar;
  Size: DWord;
begin
  Size:=250;
  GetMem(StrUserName, Size);
  GetUserName(StrUserName, Size);
  Label1.Caption:=StrPas(StrUserName);
  FreeMem(StrUserName);
end;

Get a computer name

Posted in System info

You can use GetComputerName procedure. For example:

procedure TForm1.Button1Click(Sender: TObject);
var
  CompName: array[0..256] of Char;
  i: DWord;
begin
  i:=256;
  GetComputerName(CompName, i);
  Label1.Caption:=StrPas(CompName);
end;

Get Windows directory

Posted in System info

Use GetWindowsDirectory Win32 function:

procedure TForm1.Button1Click(Sender: TObject);
var
  PWindowsDir: array [0..255] of Char;
begin
  GetWindowsDirectory(PWindowsDir,255);
  Label1.Caption:=StrPas(PWindowsDir);
end;