如何使用 Java 或 CMD 获取 PC 硬件信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6426778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 05:49:43  来源:igfitidea点击:

How to get PC Hardware information using Java or CMD

javawindowscommand-linepc

提问by Dorothy

I am creating a Java Desktop Application that is to report the Performance & Statistics of the Windows Machine (XP, Vista and W7).

我正在创建一个 Java 桌面应用程序,用于报告 Windows 机器(XP、Vista 和 W7)的性能和统计信息。

Using Java or the Command Line how do I get the following information:

使用 Java 或命令行如何获取以下信息:

  • Manufacturer (Dell, HP...)
  • Modal Number
  • Processor Type
  • Processor Size
  • System Type
  • Storage Space
  • RAM Total
  • RAM Free or Used
  • 制造商(戴尔、惠普...)
  • 模数
  • 处理器类型
  • 处理器尺寸
  • 系统类型
  • 储存空间
  • 内存总量
  • RAM 空闲或已使用

And a reference page for this would be great, in case I find more information I want to list.

如果我找到了我想列出的更多信息,那么这个参考页面会很棒。

采纳答案by Joey

Most of this should be queryable with WMI (which is what systeminfovery likely uses under the hood anyway – it just tends to gather allthere is instead of specific information).

其中大部分应该可以使用 WMI 查询(systeminfo无论如何,这很可能在幕后使用 - 它只是倾向于收集所有信息而不是特定信息)。

I hacked together the following small batch file. Not quite sure what you mean with Processor Size– no software will go into the computer case and measure the die dimensions, but maybe this comes close. You can do a setat the end of the batch file to view all created environment variables. Maybe some of them help:

我将以下小批处理文件组合在一起。不太确定你对处理器尺寸的意思- 没有软件会进入计算机机箱并测量芯片尺寸,但也许这很接近。您可以set在批处理文件的末尾执行 a查看所有创建的环境变量。也许其中一些有帮助:

@echo off
setlocal enableextensions enabledelayedexpansion

for /f "delims=" %%l in ('wmic computersystem get Manufacturer^,Model^,SystemType^,TotalPhysicalMemory /format:list') do >nul 2>&1 set "System_%%l"
for /f "delims=" %%l in ('wmic cpu get * /format:list') do >nul 2>&1 set "CPU_%%l"
for /f "delims=" %%l in ('wmic os get FreePhysicalMemory^,TotalVisibleMemorySize /format:list') do >nul 2>&1 set "OS_%%l"
set /a OS_UsedPhysicalMemory=OS_TotalVisibleMemorySize-OS_FreePhysicalMemory

for /f "delims=" %%l in ('wmic volume get DriveLetter^,FreeSpace /format:list') do (
    >nul 2>&1 set "TEMP_%%l"
    if "!TEMP_DriveLetter:~1,1!"==":" if defined TEMP_FreeSpace set StorageSpace_!TEMP_DriveLetter:~0,2!=!TEMP_FreeSpace:~0,-1!&set TEMP_DriveLetter=&set TEMP_FreeSpace=
)

echo Manufacturer: %System_Manufacturer%
echo Model: %System_Model%
echo Processor Type: %PROCESSOR_ARCHITECTURE%
echo Processor Size: %CPU_AddressWidth%
echo System Type: %System_SystemType%
echo Storage Space:
set StorageSpace_
echo RAM total: %OS_TotalVisibleMemorySize% KiB
echo RAM free: %OS_FreePhysicalMemory% KiB
echo RAM used: %OS_UsedPhysicalMemory% KiB

Side note: This is free from locale-specifics, so it should work everywhere (as opposed to things like dir | find "free"for example). Code can be found in my SVN repository.

旁注:这不受特定于语言环境的限制,因此它应该可以在任何地方使用(而不是像这样dir | find "free"的事情)。代码可以在我的 SVN 存储库中找到。

回答by Wudang

Would psinfo from sysinternals do what you want? You can run it from your server to query each PC. http://technet.microsoft.com/en-us/sysinternals/bb897550

来自 sysinternals 的 psinfo 会做你想要的吗?您可以从服务器运行它以查询每台 PC。 http://technet.microsoft.com/en-us/sysinternals/bb897550

回答by Deepak

Manufacturer

制造商

systeminfo | find "System Manufacturer"

Model Number

型号

systeminfo | find "System Model"

Processor Type

处理器类型

echo %PROCESSOR_IDENTIFIER% %PROCESSOR_LEVEL%

Processor Size

处理器尺寸

systeminfo | find "Processor"

System Type

系统类型

systeminfo | find "System type"

Storage Space

储存空间

dir | find "free"

OR

或者

fsutil volume diskfree C:

RAM Total

内存总量

systeminfo | find "Total Physical Memory"

RAM Free or Used

RAM 空闲或已使用

systeminfo | find "Available Physical Memory"