使用 Lazarus 和 FreePascal 获取 Linux 系统信息

发布于 2024-12-14 20:47:19 字数 192 浏览 2 评论 0原文

我对 Lazarus/FreePascal 非常陌生,而且之前没有 Delphi 经验。我希望能够获取 WIndows 和 Linux 上的操作系统版本信息和用户帐户类型。我看到有一个Windows系统API,但找不到类似的Linux系统API。

是否有适用于 Lazarus/FreePascal 的 Linux 系统 API?如果有,我该如何使用它?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

提笔书几行 2024-12-21 20:47:19

Linux上没有这样的统一点,你可以写一个头然后继续使用它。此外,由于 Linux 的许多部分都是独立版本的,因此不存在单一版本之类的东西。

也就是说,内核版本可以通过baseunix.fpuname()获取。发行版很难,因为每个发行版都以不同的方式存储版本信息。

第一步是确定您需要的信息,以及从哪里获取它的粗略想法(例如 libc 等系统库、sysctl 和 /proc 等附加信息,以及桌面系统上的更高级别系统是否允许查询此类信息,例如通过DBUS)。这些引用并不总是在 Pascal 中。然后在此处或 Lazarus 论坛/邮件列表上提出具体问题。

但不存在像 WMI 那样始终有效且相当不变的功能。 Linux 过去是、现在仍然是一个黑客和调整者的操作系统,被分成几个独立的发行版,几乎没有什么硬性保障。 DBUS 和 HAL 正朝这个方向发展,但版本问题和向新库的过渡使得这条路线不太通用。

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.

早乙女 2024-12-21 20:47:19
  1. 有一个“Unix”单元,你可以检查里面是否有你想要的东西。

我希望能够获取操作系统版本信息

这到底意味着什么?您可以根据需要使用“uname -a”的输出(从 TProcess 调用)。还有 /etc/redhat-release 等文件,但它们可能因发行版而异。

以及 Windows 和 Linux 上的用户帐户类型。

在 Unix 中,您可能想要查看用户所在的组。(有多种方法可以做到这一点)。

我看到有一个 Windows 系统 API,但找不到类似的 Linux 系统 API。

Linux 倾向于遵循“一切都是文件”的方法,因此某个地方通常有一个文件(或伪文件),您可以读取其中包含您想要的信息。总的来说,Unix 比 Windows 更灵活。例如,在 Windows 中,可能有一个 API 调用来获取处理器的数量或以 Mhz 为单位的速度。在 Linux 中,您可以查看 /dev/cpuinfo 并将该信息解析为文本文件。

Unix 有多种风格,甚至在 Linux 中也有多种发行版。当然,您可以通过暂时仅支持某些发行版来缩小您想要做的范围。

  1. There is a "Unix" unit, you can check if what you want is in there.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文