JAVA 读取计算机中相关信息
java读取 计算机 cup号
读取版本号
显卡
。。
。
。
。。。。。。。。
。。
。
。
。
package com.swt.common.util; import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.LineNumberReader; /**
* 获取硬件信息
* @author luoxf
*
*/
public class HardWareUtils { /**
* 获取主板序号
* @return
*/
public static String getMotherboardSN() {
String result = "";
try {
//创建暂时文件
File file = File.createTempFile("realhowto", ".vbs");
//当程序结束时候才调用跟delete有差别 (程序開始调用相对于仅仅做出声明)
file.deleteOnExit();
FileWriter fw = new 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();
} /**
* 获取CPU序列号
*
* @return
*/
public static String getCPUSerial() {
String result = "";
try {
//创建暂时文件
File file = File.createTempFile("tmp", ".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_Processor\") \n"
+ "For Each objItem in colItems \n"
+ " Wscript.Echo objItem.ProcessorId \n"
+ " exit for ' do the first cpu only! \n" + "Next \n"; // + " exit for \r\n" + "Next";
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();
file.delete();
} catch (Exception e) {
e.fillInStackTrace();
}
if (result.trim().length() < 1 || result == null) {
result = "无CPU_ID被读取";
}
return result.trim();
} /**
* 获取硬盘序列号
*
* @param drive
* 盘符
* @return
*/
public static String getHardDiskSN(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(\""
+ "c"
+ "\")\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();
} /**
* 获取MAC地址
*/
public static String getMac() {
String result = "";
try { Process process = Runtime.getRuntime().exec("ipconfig /all"); InputStreamReader ir = new InputStreamReader(process.getInputStream()); LineNumberReader input = new LineNumberReader(ir); String line=""; while ((line = input.readLine()) != null) if (line.indexOf("Physical Address") > 0) {
System.out.println(line);
String MACAddr = line.substring(line.indexOf("-") - 2); result = MACAddr; } } catch (java.io.IOException e) { System.err.println("IOException " + e.getMessage()); }
return result;
} public static void main(String[] args) {
// System.out.println("CPU SN:" + HardWareUtils.getCPUSerial());
System.out.println("主板 SN:" + HardWareUtils.getMotherboardSN()+HardWareUtils.getCPUSerial());
// System.out.println("C盘 SN:" + HardWareUtils.getHardDiskSN("c"));
// System.out.println("MAC SN:" + HardWareUtils.getMac());
} }
JAVA 读取计算机中相关信息的更多相关文章
- Java读取word中表格
因为要新建一个站,公司要把word表格的部分行列存到数据库中.之前用java操作过excel,本来打算用java从word表格中读取数据,再存到数据库中,结果因为权限不够,无法访问公司要写的那个数据库 ...
- java读取请求中body数据
java读取请求中body数据 /** * 获取request中body数据 * * @author lifq * * 2017年2月24日 下午2:29:06 * @throws IOExcepti ...
- java读取request中的xml
java读取request中的xml 答: // 读取xml InputStream inputStream; StringBuffer sb = new StringBuffer(); inpu ...
- ASP.NET Core 5.0 中读取Request中Body信息
ASP.NET Core 5.0 中读取Request中Body信息 记录一下如何读取Request中Body信息 public class ValuesController : Controller ...
- Java 读取PDF中的表格
一.概述 本文以Java示例展示读取PDF中的表格的方法.这里导入Spire.PDF for Javah中的jar包,并使用其提供的相关及方法来实现获取表格中的文本内容.下表中整理了本次代码使用到的主 ...
- springboot读取配置文件中的信息
在一个项目中,我们有时候会把一些配置信息写入到一个配置文件中,在java代码中读取配置文件的信息.在此记录下读取属性文件中的内容. 在springboot项目中,springboot的配置文件可以使用 ...
- Java 读取Word中的脚注、尾注
本文介绍读取Word中的脚注及尾注的方法,添加脚注.尾注可以参考这篇文章. 注:本文使用了Word类库(Free Spire.Doc for Java 免费版)来读取,获取该类库可通过官网下载,并解压 ...
- Java读取接口中的数据,并保存到txt文件中!
//创建读取接口中数据的方法 public static String read() { URL url = null; BufferedReader reader = null; HttpURLCo ...
- java往文本文件中写入信息并修改
题目要求: 1.可以往一个文本文档中写入员工信息:name,id和详情 2.可以更改name package FanCQ.Xue.practice; import java.io.*;import j ...
随机推荐
- 关于php上传文件过大的表单回填
也许标题有点绕口,有点无法让人理解.请原谅博主,语文学的不好,都赖体育老师. 问题场景重现:在某次迭代中,接到这样一个需求:当新建或编辑一个Bug(包含附件以及其他字段)上传附件过大时,退回到编辑页面 ...
- Needed Learning(Updating)
决定把掌握不熟练或是模型见的少的知识点在这里列一列 希望能在自己AFO前成功get技能点吧…… 优先级:动态规划-分治-字符串-图论-数据结构-数学-计算几何-其它 动态规划 1.四边形不等式优化 2 ...
- 【NOIP2014】联合权值 树上dp
题目描述 Description 无向连通图G 有n 个点,n - 1 条边.点从1 到n 依次编号,编号为 i 的点的权值为W i ,每条边的长度均为1 .图上两点( u , v ) 的距离定 ...
- IntelliJ IDEA 查看继承关系
在 IntelliJ IDEA 中这个查看一个类也就是当前类的所有继承关系,包括实现的所有的接口和继承的类, 这个继承,不仅仅是一级的继承关系,包括好几层的继承.父类的父类的父类.直到最后.可以很清楚 ...
- PostgreSQL SystemTap on Linux 转
PostgreSQL 支持动态跟踪, 可以通过dtrace或者systemtap工具统计相关探针的信息. 安装systemtap yum install systemtap kernel-debugi ...
- mysql-debug
http://www1.huachu.com.cn/read/readbookinfo.asp?sectionid=1000002778 http://hedengcheng.com/?p=238 h ...
- druid连接数据库加解密
<bean id="dataSource" class="cn.zsmy.palmdoctor.utils.DecryptDruidSource" ini ...
- KJHttp框架使用讲解
摘要 本文原创,转载请注明地址:http://kymjs.com/code/2015/05/12/01写给那些在用.想用.还没有用过KJFrame的朋友. KJFrameForAndroid总共分为四 ...
- .NET:CLR via C#:CLR Hosting And AppDomains
AppDomain Unloading To unload an AppDomain, you call AppDomain’s Unload static method.This call caus ...
- 服务信息块协议 SMB(Server Message Block protocol)
SMB(Server Message Block)是协议名,它能被用于Web连接和客户端与服务器之间的信息沟通. SMB协议 SMB最初是IBM的贝瑞·费根鲍姆(Barry Feigenbaum)研制 ...