Get Lan Group Name - Delphi

DarkCoderSc personal avatar
DarkCoderSc

Jean-Pierre LESUEUR

uses
  uHelper, System.SysUtils, Winapi.Windows;

// ...

type
  NET_API_STATUS = DWORD;

  {$A8}
  WKSTA_INFO_100 = record
    wki100_platform_id  : DWORD;
    wki100_computername : LPWSTR;
    wki100_langroup     : LPWSTR;
    wki100_ver_major    : DWORD;
    wki100_ver_minor    : DWORD;
  end;
  TWkstaInfo100 = WKSTA_INFO_100;
  PWkstaInfo100 = ^TWkstaInfo100;

// ...

const
  NERR_Success = 0;

// ...

function NetWkstaGetInfo(
  servername: LPWSTR;
  level: DWORD;
  var bufptr: Pointer
) : NET_API_STATUS; stdcall; external 'Netapi32.dll' Name 'NetWkstaGetInfo';

function NetApiBufferFree(
  Buffer : Pointer
) : NET_API_STATUS; stdcall; external 'Netapi32.dll';

// ...

function GetLangroupName() : String;
begin
  result := '';
  ///

  var pWkstaInfo : PWkstaInfo100;

  if NetWkstaGetInfo(nil, 100, Pointer(pWkstaInfo)) = NERR_Success then begin
    result := string(pWkstaInfo.wki100_langroup);

    ///
    NetApiBufferFree(pWkstaInfo);
  end;
end;

// ...

begin
  try
    WriteLn(GetLangroupName());
  except
    on e : Exception do
      WriteLn(e.Message);
  end;

// ...

Creating and researching code snippets takes time and effort. You’re welcome to share them through your own platforms, but please don’t forget to credit the original author, here: Jean-Pierre LESUEUR.


Created

July 4, 2025

Last Revised

July 4, 2025