Dave Coventry wrote: > 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'. > Result := GetEnvironmentVariable('HOSTNAME'); This won't work under windows and there is probably a better way to do this with sockets.
Andrew _______________________________________________ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus