Whare did you find that?
GetUserName( UserName : String) : String;
Ok, I did not remember the GetUserName() function. Actually its signature is :The string parameter you are referring to is not the username but the user uid (which you can get with fpgetuid).
uses users,baseunix; begin Writeln(GetUserName(fpgetuid)); end.
Not sure why the parameter name would be username which is confusing.
GetEnvironmentVariable('USER') has an advantage because it is cross-platform. IIRC it works on Windows, too. (is it so ?)On Windows it should be USERNAME so you would still need to do IFDEFs.
On Windows it should be USERNAME so you would still need to do IFDEFs.Ok, I have not done much WinAPI programming.
Can you please test if it works on Windows. My guess is that recent Windows versions have 'USER' as an alternative env.variable. If not, then we have a bug and must add IFDEFs to the function.Nope, it's just USERNAME on Windows. Not USER.
C:\Users\Rik>echo %USERNAME%
Rik
C:\Users\Rik>echo %USER%
%USER%
C:\Users\Rik>set user
USERDOMAIN=XPS420
USERDOMAIN_ROAMINGPROFILE=XPS420
USERNAME=Rik
USERPROFILE=C:\Users\Rik
1 -
2 - Rik
Ok. I fixed it in r63547.Fix confirmed on Windows.
Now Source -> Insert General -> "Current Username" should work also on Windows.
Source -> Insert General -> "ChangeLog Entry"results in:
12-07-2020 Rik <Rik@>
Ok. If there is a sensible way to fix it, I can apply a patch. However it sounds like COMPUTERNAME would not be very useful in GetCurrentMailAddress.HOSTNAME (of a linux machine) is also not very sensible in a emailaddress.
In r63552 I renamed the function as GetCurrentChangeLog and added COMPUTERNAME for Windows.Fix confirmed on Windows
13-07-2020 Rik <Rik@XPS8500>
Strange. In my Manjaro Linux the ChangeLog Entry gives :Code: [Select]13-07-2020 Rik <Rik@XPS8500>
13.07.2020 juha <juha@>
It means HOSTNAME gives an empty string. However it works in console :$ echo $HOSTNAME
juha-fp30
USER works as expected in both cases :$ echo $USER
juha
That was discussed in a recent topic.Strange. In my Manjaro Linux the ChangeLog Entry gives :Code: [Select]13-07-2020 Rik <Rik@XPS8500>
Code: [Select]13.07.2020 juha <juha@>
It means HOSTNAME gives an empty string. However it works in console :Code: [Select]$ echo $HOSTNAME
USER works as expected in both cases :
juha-fp30Code: [Select]$ echo $USER
juha
And that works with any user?Now you can proceed like in every other Linux.
env HOSTNAME=MySweetRaspi
root@sonarr:~# env HOSTNAME=MySweetRaspi
SHELL=/bin/bash
SUDO_GID=1000
SUDO_COMMAND=/bin/bash
SUDO_USER=pi
NO_AT_BRIDGE=1
PWD=/root
LOGNAME=root
HOME=/root
LANG=en_GB.UTF-8
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
TERM=xterm
USER=root
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SUDO_UID=1000
MAIL=/var/mail/root
TEXTDOMAIN=Linux-PAM
_=/usr/bin/env
HOSTNAME=MySweetRaspi
root@sonarr:~# env | grep HOST
root@sonarr:~#
No - if you make changes in the environment then you should be of courseWhich is why it's better to use gethostname().
root
Which is why it's better to use gethostname().
/quote]
I think it is better to have somehthing like a default Linux.
But as you like .....
Winni
Hi!So this is actually quite a problem, because not everyone has root access. One could go into his user profile and set there HOSTNAME=$(cat /proc/sys/kernel/hostname), but again thats just a hack.
No - if you make changes in the environment then you should be of course
root
Winni
I think it is better to have somehthing like a default Linux.I would like that too.
But as you like .....
I think it is better to have somehthing like a default Linux.
But as you like .....
Winni
That was discussed in a recent topic.Right! I saw that thread but didn't read it carefully.
https://forum.lazarus.freepascal.org/index.php/topic,50533.0.html
Whare did you find that?
I don't seeWhare did you find that?
users.pas unit users; Interface {$mode delphi} uses UnixType,BaseUnix,pwd,grp, {$ifdef Linux} shadow,{$endif}SysUtils,Classes; Type EUserLookupError = Class(Exception); EGroupLookupError = Class(Exception); EShadowLookupError = Class(Exception); TPasswordRecord = Tpasswd; PPasswordRecord = ^TPasswordRecord; { User functions } Function getpwnam(Const UserName: String) : PPasswordRecord; Procedure GetUserData(Const UserName : String; Var Data : TPasswordRecord); overload; Procedure GetUserData(Uid : TUID; Var Data : TPasswordRecord); overload; function GetUserName(UID : TUID) : String; function GetUserId(Const UserName : String) : TUID; function GetUserGid(Const UserName : String) : TGID; function GetUserDir(Const UserName : String): String; function GetUserDescription(Const UserName : String): String; Procedure GetUserList(List : Tstrings);overload; Procedure GetUserList(List : TStrings; WithIDs : Boolean);overload; [code]
Writeln(GetUserName(fpgetuid));
Thanks, that works perfectly for me. I got it from "users.pas" after a search here. I could not find anything else that alluded to getting the User-Name with out first knowing it. Not even the Wiki.
With the discussion that has followed my first post, I am not sure if I should mark it SOLVED or not. :)
If somebody knows about Amiga HostName, please tell me (PM, mail).
* And what a trip to the past has been setting up and on again those venerable granpas! :D
* And what a trip to the past has been setting up and on again those venerable granpas! :D
You young whipper snappers: When I started programming there was no Borland and no Turbo anything. Tandy Model I with 4K of memory and cassette recorder for 300-BAUD data. Livin' the fast life.
I started in the early 1980s with a Sinclair Spectrum 48k, a B/W TV set we "forgot" to trash, and reading/writing tapes with my father's Hi-Fi tower.
I applied the function GetCurrentChangeLog change in r63554. I guess the GetHostName stuff was little out of topic in this GetUserName thread.As already mentioned by others, Amiga did not had hardware to connect to a network by default.
If somebody knows about Amiga HostName, please tell me (PM, mail).
Question about Amiga: does it need special treatment? Does it have 'COMPUTERNAME'?It does when that specific environment variable is set ;) (e.g., no it does not have that environment variable by default. I am not aware of any software that does supply this particular name).
PS https://wiki.amigaos.net/wiki/AmigaOS_Manual:_AmigaDOS_Command_Reference (https://wiki.amigaos.net/wiki/AmigaOS_Manual:_AmigaDOS_Command_Reference)
Currently there is officially no support for that platform as there is (again officially) no maintainer. Support is offered for AmigaOS3.x, AROS and MorphOS. The classic AmigaOS1.x and modern AmigaOS4.x targets are officially not supported and should therefore be considered unmaintained. Current maintainers do try to keep things going, but only to a certain level and when time permits.
The best solution to that imho would be to solve it just as ApplicationName (https://www.freepascal.org/docs-html/rtl/sysutils/applicationname.html) and VendorName (https://www.freepascal.org/docs-html/rtl/sysutils/vendorname.html) do it by providing a custom override for the enduser, such as OnGetApplicationName (https://www.freepascal.org/docs-html/rtl/sysutils/ongetapplicationname.html) and OnGetVendorName (https://www.freepascal.org/docs-html/rtl/sysutils/vendorname.html)I believe it is a good idea but not in the scope of the Lazarus IDEProcs helper function. It should probably be part of FPC's libs.
That way you are able to provide a default implementation (depending on the platform), but at same time let the implementation details over to the end-user in case end-user environment requires it.
Would that be an option ?
Well, AmigaOS1.x is not yet supported. Charlie is improving the RTL step by step to get it working there as well.Yes, I know ;)
Also we do have an official AmigaOS4.x release (https://freepascal.org/down/powerpc/amigaos-hungary.html). It's just that the target is not getting as much love as the other Amiga-likes and the X5000 is not supported.I am aware there is a release. Reason there is not much love is (mostly) that there seems to be no interest from that camp and the hardware you mention is ridiculously expensive. Both Marcus and Charlie expressed not wanting to partake in that, at least last time I spoke them. Neither do I have any interest other then what I already contribute.
I believe it is a good idea but not in the scope of the Lazarus IDEProcs helper function. It should probably be part of FPC's libs.Ah ok. I was already a bit lost on where to find this function. Yes, I agree that should belong to FPC, not Laz.
I have understood that Lazarus really runs on Amiga which I find amazing! I don't know how many people are testing it.I do hope no-one ;)
But, you probably know that already ;D