Вы можете использовать NetGetJoinInformation :
program test;
{$APPTYPE CONSOLE}
{$MINENUMSIZE 4}
uses
Windows, SysUtils;
const
netapi = 'netapi32.dll';
type
TNetSetupJoinStatus = (NetSetupUnknownStatus, NetSetupUnjoined, NetSetupWorkgroupName, NetSetupDomainName);
function NetApiBufferFree(Buffer: Pointer): DWORD; stdcall; external netapi;
function NetGetJoinInformation(lpServer: PWideChar; out lpNameBuffer: PWideChar;
out BufferType: TNetSetupJoinStatus): Cardinal; stdcall; external netapi;
procedure NetApiCheck(RetValue: Cardinal);
begin
if RetValue <> ERROR_SUCCESS then
RaiseLastOSError(RetValue);
end;
function GetJoinInfo(out JoinStatus: TNetSetupJoinStatus): WideString;
var
P: PWideChar;
begin
NetApiCheck(NetGetJoinInformation(nil, P, JoinStatus));
Result := P;
NetApiBufferFree(P);
end;
procedure Main;
const
JoinStatusStrings: array[TNetSetupJoinStatus] of string = ('Unknown', 'Unjoined', 'Workgroup', 'Domain');
var
Info: TNetSetupJoinStatus;
S: WideString;
begin
S := GetJoinInfo(Info);
Writeln(Format('%s %s', [JoinStatusStrings[Info], S]));
end;
begin
try
Main;
except
on E: Exception do
begin
ExitCode := 1;
Writeln(Format('[%s] %s', [E.ClassName, E.Message]));
end;
end;
end.