Beranda > Delphi > Get the network computer and domain names

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.

Iklan
Kategori:Delphi
  1. Juli 26, 2014 pukul 2:33 am

    Hi there! Do you know if they make any plugins to help with SEO? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good results. If you know of any please share. Thanks! For news and guidance about how to Create A Website visit 4buildwebsite.blogspot.com.

  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: