使用Oshi Java库获取Windows PE的硬件和操作系统信息

huangapple go评论106阅读模式
英文:

Use Oshi Java library to get hardware and operating system information for Windows PE

问题

我无法在Windows PE上运行我的Java应用程序。基本上,我的应用程序获取硬件和操作系统信息的数据。我正在使用Oshi Java库来实现这个目的,但Oshi使用了JNA库,而JNA库不断崩溃。

注意:我的应用程序在任何其他操作系统上都可以正常运行,但无法在Windows PE上运行。我正在使用的代码如下:

HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();

hal.getComputerSystem();

任何帮助将不胜感激。

英文:

I am unable to run my Java app on Windows PE. Basically, my application gets data of Hhardware plus operating system information. I am using Oshi Java library for this purpose, but Oshi uses the JNA library, which is continuously crashing.

Note: My application runs fine on any other OS, but is unable to run on Windows PE. Code that I am using is as follows:

HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();

hal.getComputerSystem();

Any help will be appreciated.

答案1

得分: 6

我是 OSHI 的作者/主要维护者,也是 JNA 的贡献者。JNA 的 Platform 类 在 Windows 和 Windows PE 之间没有区分。OSHI 的代码依赖于标准的 Windows Version Helper API 来确定 DLL 函数的操作系统支持情况。然而,Windows PE 并没有被指示为一个独立的版本。

实际上,Windows PE 不是设计成一个独立的操作系统。它的用途(和授权使用)非常有限。根据 Windows PE 文档(我强调):

> Windows PE 不是通用的操作系统。除部署和恢复之外,不得用于任何其他目的。

此外,

> 为了防止其用作生产操作系统,Windows PE 在连续使用 72 小时后会自动停止运行 shell 并重新启动。

基本上,Windows 10 API 中的一些功能在 PE 中不可用。从 这些微软文档 中可以看出:

> API 兼容性参考
>
> Windows PE 是一个基于 Windows 操作系统一部分组件的轻量级引导操作系统。它旨在托管部署和恢复应用程序。因此,它包含许多 Windows 二进制文件,这些文件需要托管这些类别应用程序最重要的 API。由于尺寸和其他设计限制,并非所有的 Windows 二进制文件都存在于 Windows PE 中,因此并非所有的 Windows API 都可用

这是 WinPE 的特性,而不是 bug。

OSHI 被设计为一个跨平台的库,用于提供信息。它不是一个“部署和恢复”应用程序。OSHI 通过 JNA 链接到标准的 Windows DLL,如 Kernel32,而 WinPE 则有其自己的一套 MinCore DLL

Windows PE 的目标是非常轻量级的,非常针对 Windows 操作系统系列,非常针对部署和恢复任务。

在进行“部署和恢复”所需的操作系统和硬件信息方面,您可能应该使用命令行或者 Powershell 工具,Windows PE 的唯一授权使用场景。OSHI 的 ExecutingCommand 类是一个很好的实用类,用于将命令行响应处理为 Java 字符串,您可以随意复制并在自己的 Java 项目中使用,而无需引入整个 OSHI/JNA 的依赖。

如果您能具体指出“JNA 崩溃”的特定情况,我可以帮助您找到解决异常的方法。或者,您也可以在 OSHI 项目上提交问题/功能请求,以使其在 PE 环境中更加稳定,尽管“更加稳定”很可能是指“避免崩溃”,而不是提供 Windows API 在 WinPE 中不可用的信息。最后,您也可以选择在 JNA 邮件列表上展开讨论,讨论您的问题。

英文:

I'm the author/primary maintainer of OSHI and a committer at JNA. JNA's Platform class does not distinguish between Windows and Windows PE. OSHI's code relies on the standard Windows Version Helper API to determine OS support for DLL functions. However, Windows PE is not indicated as a separate version.

In fact, Windows PE is not designed to be a standalone operating system. Its purpose (and authorized use) is very limited. From the Windows PE docs (emphasis mine):

> Windows PE is not a general-purpose operating system. It may not be used for any purpose other than deployment and recovery.

Further,

> To prevent its use as a production operating system, Windows PE automatically stops running the shell and restarts after 72 hours of continuous use.

Essentially, some features available in the Windows 10 API are not present in PE. From these Microsoft docs:

> API Compatibility reference
>
> Windows PE is a lightweight, bootstrap operating system based on a subset of components from the Windows operating system. It is designed to host deployment and recovery apps. As such, it contains many Windows binaries that are needed to host the APIs that are most important to these classes of app. Due to size and other design constraints, not all Windows binaries are present in Windows PE, and therefore not all Windows APIs are present or usable.

This is a feature of WinPE, not a bug.

OSHI is designed as a cross-platform library to provide information. It is not a "deployment and recovery" app. OSHI links (via JNA) to standard Windows DLLs such as Kernel32, while WinPE has its own set of MinCore DLLs.

Windows PE is intended to be very lightweight, and very specific to the Windows operating system family, and very specific to deployment and recovery tasks.

You should probably be using command-line or Powershell tools for operating system and hardware information necessary for "deployment and recovery", the only authorized uses of WinPE. OSHI's ExecutingCommand class is a nice utility class for processing command-line responses as Java Strings, that you are welcome to copy and use in your own Java project, without the overhead of the entire OSHI/JNA dependencies.

If you can specify specific points where "JNA is crashing" I can help you identify ways to work around any exceptions that may be thrown. Alternately, you can submit an issue/feature request at the OSHI project identifying these failures, to make it more robust to the PE environment, although "more robust" will likely be in the form of "avoiding crashes" rather than in providing information that is not available from the Windows API in WinPE. Finally, you may choose to bring up your issues for an extended discussion on the JNA mailing list.

答案2

得分: 2

根据我所了解,Oshi不支持Windows PE:

  • Oshi的常见问题解答中未提及支持Windows PE。对于Windows,它列出了:

    支持Windows 7及更高版本。(几乎所有功能在Vista上都可用,在Windows XP上的大部分功能也可用。)

  • 我在Oshi问题跟踪器中未找到任何提到Windows PE的问题。

  • 当我搜索“oshi windows pe”时,没有相关的内容出现。

  • 代码库中有一个属性文件,将Windows操作系统的标识映射到名称。其中未提及任何Windows PE的版本号。

  • JNA库的文档中未提及Windows PE。

尽管这些事实都不是决定性的,但综合起来可以形成一个清晰的画面。


这并不是说Oshi不能支持Windows PE。但要取得一些进展,您需要提供更多细节;例如,告诉我们它是如何崩溃的。

英文:

From what I can tell, Oshi does not support Windows PE:

  • The Oshi FAQ does not mention Windows PE as support. For Windows, it lists:

    > Windows 7 and higher. (Nearly all features work on Vista and most work on Windows XP.)

  • I found no issues in the Oshi issue tracker that mention Windows PE

  • When I Googled for "oshi windows pe", nothing relevant showed up.

  • There is a property file in the codebase that maps Windows OS ids to names. It does not mention any Windows PE version numbers.

  • The JNA library documentation makes no mention of Windows PE.

None of these facts is conclusive, but taken together they paint a clear picture.


This is not to say that Oshi could not support Windows PE. But to make some progress you would need to provide more details; e.g. tell us how it is crashing.

huangapple
  • 本文由 发表于 2020年7月27日 20:12:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/63115077.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定