Help & Manual authoring tool
How to get the computer's network name?

Getting the computer's network name

Copyright © 2000 Ernesto De Spirito

Storage Library - Save your app's configuration

GetComputerName

If we want to know the name that identifies in a network the machine that is running our program, we can use the API Windows function GetComputerName that gives us the NetBIOS name of the local computer. The following function excapsulates the call to this API to return the machine name as a string:

uses Windows;

function GetComputerNetName: string;
var
  buffer: array[0..255] of char;
  size: dword;
begin
  size := 256;
  if GetComputerName(buffer, size) then
    Result := buffer
  else
    Result := ''
end;

Windows 2000 users can use the API GetComputerNameEx that appart from the NetBIOS name allows the retrieval of diverse DNS names.

Sample call

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(GetComputerNetName);
end;
JfControls Library - for Delphi and C++ Builder
Copyright © 2000/2006 Ernesto De Spirito.   All rights reserved.