I am really new to Lazarus/FreePascal and I have no prior Delphi experience. I want to be able to get OS version information and user account type on both WIndows and Linux. I saw that there is a Windows system API, but could not find anything similar for Linux.
Is there a Linux system API for Lazarus/FreePascal and if so, how can I use it?
There is no such unified point on Linux, for which you could write one header and then keep using it. Moreover, since many parts of Linux are independently versioned, there is no such thing as a single version.
That being said, kernel version can be gotten via baseunix.fpuname(). Distribution version is hard, since each distribution stores his version info in a different way.
First step would be to identify the information you need, and a rough idea where to get it (e.g. system libraries like libc, additional info like sysctl and /proc, and if higher level systems on desktop systems allow to query such info, e.g. via DBUS). Those references won't be in Pascal always. Then ask specific questions here, or on the Lazarus forums/maillists.
But there is no WMI like functionality that always works and is pretty invariant. Linux is and remains a hacker and tweaker OS fragmented into separate distributions with few hard securities. DBUS and HAL were going in that direction, but versionitis and the transition to a new library made this route less universal.
I want to be able to get OS version information
What does this mean exactly? You can use the output of "uname -a" (Called from TProcess), depending on your needs. There are also files like /etc/redhat-release, etc., but they may vary by distribution.
and user account type on both Windows and Linux.
Probably what you want in Unix is to see what groups the user is in. (There are various ways to do this).
I saw that there is a Windows system API, but could not find anything similar for Linux.
Linux tends to follow the "Everything is a file" approach, so somewhere there is usually a file (or pseudo-file) you can read with the information you want. In general, Unix is more flexible than Windows. For example, in Windows there is probably an API call to get the number of processors or speed in Mhz. In Linux, you can look in /dev/cpuinfo and parse that info as a text file.
There are various flavors of Unix, and even within Linux, various distributions. You can of course narrow the scope of what you want to do by supporting only certain distributions for the time being.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With