Thursday, September 10, 2009

Get/Set Computer Name?

Need to get/set the computer name?

Get function
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;

Set function
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;

No comments:

Post a Comment

Blogroll(General programming and Delphi feeds)