«« 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

How to get and set the local computer name

   

Here are two routines, one to read the computer name and the other to set it.

function GetPCName: string;
var
  buffer: array[0..MAX_COMPUTERNAME_LENGTH + 1] of Char;
  Size: Cardinal;
begin
  Size := MAX_COMPUTERNAME_LENGTH + 1;
  Windows.GetComputerName(@buffer, Size);
  Result := StrPas(buffer);
end;

function SetPCName(AName: string): Boolean;
var
  PCName: array[0..MAX_COMPUTERNAME_LENGTH + 1] of Char;
  Size: Cardinal;
begin
  StrPCopy(PCName, AName);
  Result := Windows.SetComputerName(PCName);
end;

SetPCName will fail unless the current user has administrator rights.

Author: Unknown
Contributor: Topellina
Added: 2010-12-17
Last updated: 2010-12-17

« Return to contents »