Question:
How to Set and Retrieve My Computer Name?

Answer:
Simple way is to use GetComputerName and SetComputerName function.
You can clearly check this example.


function GetComputerName: 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 SetComputerName(AComputerName: string): Boolean;
var
ComputerName: array[0..MAX_COMPUTERNAME_LENGTH + 1] of Char;
Size: Cardinal;
begin
StrPCopy(ComputerName, AComputerName);
Result := Windows.SetComputerName(ComputerName);
end;



5 Responses so far.

Post a Comment

Thank you for your comment.

Any request and idea are welcome.

CLICK TO REGISTER