«« Site Rescued »»

While the site is still going to move from its current host, a new site will now take its place. More Info.

The new site may have less content, but the core will now remain. And it will now play nicely with phones! Keep an eye on the DelphiDabbler Blog for news.

» Help

Get the network computer and domain names

   

This tip shows how to get the network computer and domain names.

const
  NERR_Success = 0;

function NetWkstaGetInfo(ServerName: LPWSTR; Level: DWORD;
  BufPtr: Pointer): Longint; stdcall;
  external 'netapi32.dll' Name 'NetWkstaGetInfo';

type
  WKSTA_INFO_100 = record
    wki100_platform_id: DWORD;
    wki100_computername: LPWSTR;
    wki100_langroup: LPWSTR;
    wki100_ver_major: DWORD;
    wki100_ver_minor: DWORD;
  end;
  LPWKSTA_INFO_100 = ^WKSTA_INFO_100;

  _USER_INFO_0 = record
    usri0_name: LPWSTR;
  end;

function GetNetParam(AParam: Integer): string;
var
  PBuf: LPWKSTA_INFO_100;
  Res: LongInt;
begin
  Result := '';
  Res := NetWkstaGetInfo(nil, 100, @PBuf);
  if Res = NERR_Success then
  begin
    case AParam of
      0: Result := string(PBuf^.wki100_computername);
      1: Result := string(PBuf^.wki100_langroup);
    end;
 end;
end;

function GetComputerName: string;
begin
  Result := GetNetParam(0);
end;

function GetDomainName: string;
begin
  Result := GetNetParam(1);
end;

Call GetComputerName and GetDomainName to display the required names.

Look up NetWkstaGetInfo in Window help or on MSDN for information on how this works.

Author: Joe Donth
Contributor: Joe Donth
Added: 2008-03-31
Last updated: 2008-03-31

« Return to contents »