const
falsch = '*** FEHLER ***';
function PC_Name: string; overload;
var
g: Longword;
p: Pchar;
begin
result := falsch;
g := MAX_COMPUTERNAME_LENGTH + 1;
p := StrAlloc(g);
if GetComputerName(p, g) then result := p;
StrDispose(p);
end;
function PC_Name(n: string): boolean; overload;
begin
result := (length(n) <= MAX_COMPUTERNAME_LENGTH)
and SetComputerName(pchar(n));
end;
// Computername auslesen
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(pc_name);
end;
// Computername setzen
procedure TForm1.Button2Click(Sender: TObject);
begin
if not pc_name('MyName 001') then
showmessage(falsch) else
showmessage('Sie müssen jetzt den Computer neu starten.');
end;