Hi,

I'm trying to get the name of the computer my app is running on.

I've tried this:


function GetThisComputerName: string;
var
  c: array[0..127] of Char;
  computer: string;
  sz: dword;
  AProcess: TProcess;
  AStringList: TStringList;

begin
{$IFDEF Win32}
  sz := SizeOf(c);
  GetComputerName(c, sz);
  Result := c;
{$ELSE}
  AProcess := TProcess.Create(nil);
  AStringList := TStringList.Create;
  AProcess.CommandLine := 'echo $HOSTNAME';
  AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
  AProcess.Execute;
  AStringList.LoadFromStream(AProcess.Output);
  Result:=AStringList.Strings[0];
  AStringList.Free;
  AProcess.Free;
{$ENDIF}

end;

I'm not sure if it works under Windows, but running Ubuntu, it returns
'$HOSTNAME'.

Can anyone see what I'm doing wrong, or offer an alternative way of
getting the name of the computer?
_______________________________________________
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to