java获取CPU与硬盘的ID号?或调用JNI获取,急用!!!!

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java获取CPU与硬盘的ID号?或调用JNI获取,急用!!!!相关的知识,希望对你有一定的参考价值。

各位!!!!有谁知道java现在能不能直接实现获取CPu或硬盘的ID的方法,如果没法谁能给个C或C++的获取CPU与硬盘的ID的代码以便实现JAVA的JNI调用,真的很急用,谢谢了!!

可以用SNMP协议,一般的操作系统都会实现SNMP协议,该协议可以取得你感兴趣的计算机的数据,比如CPU,磁盘,内存,等等信息,一般用来做监控计算机信息的一种方式来用,可以去找找SNMP4J的jar及相关文档 参考技术A 虽然我没有做过这个 ,但是java和操作系统的通信应该不是问题吧, 访问操作系统的api接口获取此信息当然就更不是问题了吧

java 能不能获取CPU的ID号,硬盘的序列号

///==============================获取CPU序列号========
package com.test;
import java.io.IOException;
import java.util.Scanner;

public class CpuUtil
public static void main(String[] args) throws IOException
long start = System.currentTimeMillis();
Process process = Runtime.getRuntime().exec(
new String[] "wmic", "cpu", "get", "ProcessorId" );
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String property = sc.next();
String serial = sc.next();
System.out.println(property + ": " + serial);
System.out.println("time:" + (System.currentTimeMillis() - start));



//=======================获取硬盘序列号==========================
package com.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;

public class DiskUtil
public static String getSerialNumber(String drive)
String result = "";
try
File file = File.createTempFile("realhowto",".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
+"Set colDrives = objFSO.Drives\n"
+"Set objDrive = colDrives.item(\"" + drive + "\")\n"
+"Wscript.Echo objDrive.SerialNumber"; // see note
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null)
result += line;

input.close();

catch(Exception e)
e.printStackTrace();

return result.trim();

public static void main(String[] args)
String sn = DiskUtil.getSerialNumber("C");
System.out.println(sn);


//=============================获取主板序列号====================
package com.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;

public class MiscUtil
public static String getMotherboardSN()
String result = "";
try
File file = File.createTempFile("realhowto", ".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
+ "Set colItems = objWMIService.ExecQuery _ \n"
+ " (\"Select * from Win32_BaseBoard\") \n"
+ "For Each objItem in colItems \n"
+ " Wscript.Echo objItem.SerialNumber \n"
+ " exit for ' do the first cpu only! \n" + "Next \n";
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec(
"cscript //NoLogo " + file.getPath());
BufferedReader input = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
while ((line = input.readLine()) != null)
result += line;

input.close();
catch (Exception e)
e.printStackTrace();

return result.trim();

public static void main(String[] args)
String cpuId = MiscUtil.getMotherboardSN();
System.out.println(cpuId);


参考技术A 可以,JNA、 JNI 就可以的了 。。。。。。

以上是关于java获取CPU与硬盘的ID号?或调用JNI获取,急用!!!!的主要内容,如果未能解决你的问题,请参考以下文章

java 能不能获取CPU的ID号,硬盘的序列号

jni调用 java和c是同个线程吗

用java获得机器的唯一号

C# 获取本机CPU序列号,MAC地址,硬盘ID,本机IP地址,计算机名,物理内存,PC类型

批处理 命令获取主板序列号 硬盘序列号 CPU ID?

java怎样获取CPU占用率和硬盘占用率