如何使用Java或CMD获取PC硬件信息 [英] How to get PC Hardware information using Java or CMD

查看:937
本文介绍了如何使用Java或CMD获取PC硬件信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Java桌面应用程序,用于报告性能&使用Java或命令行如何获取以下信息:





  • 制造商(Dell,HP ...)

  • 模式号

  • 处理器类型

  • 处理器大小

  • 系统类型

  • 储存空间



  • 不需要使用RAM。



解决方案

大多数应该可以用WMI查询(这是 systeminfo 很可能在引擎盖下使用 - 它只是倾向于收集所有,而不是具体的信息)。



我一起黑了下面的小批量文件。不太确定你的意思与处理器大小 - 没有软件将进入计算机的情况下,测量模具尺寸,但也许这是接近。您可以在批处理文件末尾执行 set 来查看所有创建的环境变量。也许有些人帮助:

  @echo off 
setlocal enableextensions enabledelayedexpansion

for / fdelims =%% l in('wmic computersystem get Manufacturer ^,Model ^,SystemType ^,TotalPhysicalMemory / format:list')do> nul 2>& 1 setSystem _ %% l
for / fdelims =%% l in('wmic cpu get * / format:list')do> nul 2>& 1 setCPU _ %% l
for / fdelims = %% l in('wmic os get FreePhysicalMemory ^,TotalVisibleMemorySize / format:list')do> nul 2>& 1 setOS _ %% l
set / a OS_UsedPhysicalMemory = OS_TotalVisibleMemorySize-OS_FreePhysicalMemory

for / fdelims =%% l in('wmic volume get DriveLetter ^,FreeSpace / format:list')do(
> nul 2>& 1 setTEMP _ %%如果定义了TEMP_FreeSpace set StorageSpace_!TEMP_DriveLetter:〜0,2!=!TEMP_FreeSpace:〜0,-1!& set TEMP_DriveLetter =TEMP_DriveLetter: & set TEMP_FreeSpace =


echo制造商:%System_Manufacturer%
echo模型:%System_Model%
echo处理器类型:%PROCESSOR_ARCHITECTURE%
处理器大小:%CPU_AddressWidth%
echo系统类型:%System_SystemType%
echo存储空间:
set StorageSpace_
回显RAM总数:%OS_TotalVisibleMemorySize%KiB
echo RAM free :%OS_FreePhysicalMemory%KiB
使用的回声RAM:%OS_UsedPhysicalMemory%KiB

没有区域设置,所以它应该在任何地方工作(而不是像 dir |例如找到free)。代码可以在我的SVN存储库中找到


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

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

  • Manufacturer (Dell, HP...)
  • Modal Number
  • Processor Type
  • Processor Size
  • System Type
  • Storage Space
  • RAM Total
  • RAM Free or Used

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

解决方案

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

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 set at the end of the batch file to view all created environment variables. Maybe some of them help:

@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.

这篇关于如何使用Java或CMD获取PC硬件信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆