- 浏览: 756649 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (163)
- java-Excel (2)
- java-SSH (19)
- java-SVN (2)
- java-dwr (1)
- java-Liferay (2)
- wiki-LDAP (1)
- java-jDom (1)
- LDAP (2)
- javaScript (8)
- 数据挖掘 (1)
- java-mail (1)
- java-webService (2)
- Oracle/MySql/SqlServer2k/Sybase (3)
- db-sql (3)
- 社保 (3)
- 英语资料 (1)
- 杂谈 (31)
- 设计模式 (1)
- java-webwork (1)
- java-eclipse (3)
- java-Maven (2)
- WS/SOA/ESB (1)
- java-jfreechart (1)
- 手机开发 (4)
- linux (9)
- 搜索 (1)
- Tomcat/Weblogic (6)
- CVS/Subversion (1)
- eStore (3)
- 企业家 (0)
- java-JDBC (1)
- C/C++ (3)
- Car (2)
- Dos/Shell (1)
- 算法 (2)
- English Learning (4)
- Marriage (3)
- 心灵修行 (2)
- UML及模型设计 (0)
- 数据库设计 (1)
- 资源 (1)
- 下载 (7)
- 职业之路 (4)
- 网站安全 (1)
- StateStreet (1)
- 测试 (0)
- 性能测试 (3)
- Cloud Computing (0)
- 文档管理 (0)
- 弹性云平台 (4)
- 面试必知必会 (1)
最新评论
-
forrest_lv:
博主是其中一员?
浙江大学0X级计算机和软件学院研究生就业状况 (转) -
showtimes52007:
lz实现的拷贝方法是io的,我前几天也写了个拷贝文件的方法,只 ...
文件拷贝 -
bo_hai:
总结的很好呀!谢谢呀!S
MySql用户创建、授权以及删除 -
pengzhenyi:
对于初学者来说这本书不错滴
spring_in_action_中文版 -
soundycui:
只有6-10章节
spring_in_action_中文版
Get the hard disk serial number or Motherboard serial numberTag(s): Varia
When you need to know hardware details, Java is not the best tool unless you call a JNI routine or an external utility. The JNI solution is always the best because it is designed to interact closely with Java but it may be more complex to develop. If your need is simple (no interaction) and the need to be cross plateform is not present then calling an external utility is maybe "a good enough" choice.
In these 2 examples, we create the appropriate VBS script file on-the-fly and capture its output. They are very Windows oriented since they rely on the "Windows Script Host" to execute the generated scripts.
The vbscript queries a WMI class to get a specific hardware information. Here we are using the Win32_BaseBoard but they are many others, see http://msdn2.microsoft.com/en-us/library/aa389273.aspx for complete list.
Motherboard serial number
import java.io.File;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class MiscUtils {
private MiscUtils() { }
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 = MiscUtils.getMotherboardSN();
javax.swing.JOptionPane.showConfirmDialog((java.awt.Component)
null, cpuId, "Motherboard serial number",
javax.swing.JOptionPane.DEFAULT_OPTION);
}
}
Hard disk serial number
This serial number is created by the OS where formatting the drive and it's not the manufacturer serial number. It's unique, because it is created on the fly based on the current time information. AFAIK, there is no API that return that the manufacturer SN. At best, the SN of the HD firmware can be read but this will involve some very low-level API calls. Keep in mind that even if you get that number, there is no warranty that it will be unique since each manufacturer can assign the SN as they wish.
import java.io.File;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class DiskUtils {
private DiskUtils() { }
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 = DiskUtils.getSerialNumber("C");
javax.swing.JOptionPane.showConfirmDialog((java.awt.Component)
null, sn, "Serial Number of C:",
javax.swing.JOptionPane.DEFAULT_OPTION);
}
}
NOTE : Other properties : objDrive.AvailableSpace/DriveType/FileSystem/IsReady <!-- HOWTO content -->
import java.io.File; import java.io.FileWriter; import java.io.BufferedReader; import java.io.InputStreamReader; public class MiscUtils { private MiscUtils() { } 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 = MiscUtils.getMotherboardSN(); javax.swing.JOptionPane.showConfirmDialog((java.awt.Component) null, cpuId, "Motherboard serial number", javax.swing.JOptionPane.DEFAULT_OPTION); } }
import java.io.File; import java.io.FileWriter; import java.io.BufferedReader; import java.io.InputStreamReader; public class DiskUtils { private DiskUtils() { } 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 = DiskUtils.getSerialNumber("C"); javax.swing.JOptionPane.showConfirmDialog((java.awt.Component) null, sn, "Serial Number of C:", javax.swing.JOptionPane.DEFAULT_OPTION); } }
发表评论
-
Http Client 访问网页。
2012-03-16 01:03 895http://hc.apache.org/httpclient ... -
jsoup posting and cookie
2012-03-16 00:48 652http://stackoverflow.com/questi ... -
使用 jsoup 对 HTML 文档进行解析和操作(比HTMLParser好)
2012-03-15 23:01 1876jsoup 简介 Java 程序在解析 HTML 文档时 ... -
Jackson 入门 【转】
2012-03-14 23:51 1823同事的一些测试结果看来,Jackson在处理Json方面性 ... -
Hibernate Call SPs
2011-04-26 21:09 1127First I am going to post the Na ... -
Struts2中文乱码问题
2008-11-25 20:44 2236Struts2中文乱码问题 有一段时间没做Struts2开发了 ... -
hibernate3.04中文文档
2008-08-01 23:20 1494hibernate3.04中文文档.rar </ta ... -
spring_in_action_中文版
2008-07-31 21:25 2174[url=../../../topics/download/e ... -
AOP和AspectJ-扫盲(转)
2008-06-06 12:18 1413原贴:http://www.jdon.com/AO ... -
appfuse学习手记
2008-03-11 13:31 18751。package com.mycompany.app.dao ... -
Struts--Ajax应用例码
2007-11-09 13:10 1485js 代码 new Element.update ... -
Struts+Spring+Hibernate实现上传下载
2007-08-29 10:54 1832下载本文源代码 ... -
Spring配置代码范例
2007-07-25 17:19 1695Spring配置代码 < ... -
加载Spring的 Web.xml配置
2007-07-25 17:12 21192xml 代码 <?xml versio ... -
Commons-logging + Log4j 入门指南
2007-07-18 15:55 1268一 :为什么同时使用commons-logging和Log4j ... -
spring -struts plugin
2007-07-16 15:23 1844struts-config.xml xml 代码 ... -
Log4j设置
2007-07-16 14:49 21711.commons-logging.properties or ... -
过滤器设置
2007-07-16 14:45 14741。SetCharacterEncodingFilter 代码 ...
相关推荐
在Java编程环境中,读取硬盘序列号是一项常见的需求,特别是在软件授权、系统识别或设备管理等领域。硬盘序列号是每个硬盘制造商为生产出的每个硬盘分配的唯一标识符,类似于设备的身份证。以下将详细解释如何使用...
在Java编程环境中,读取硬盘序列号是一项常见的需求,特别是在系统管理、设备识别或软件授权等领域。硬盘序列号是每个硬盘制造商赋予的唯一标识符,它可以帮助我们区分不同的硬盘。以下是一个详细的Java实现方法,...
Wscript.Echo objItem.SerialNumber exit for ' do the first CPU only! Next ``` 2. 使用Java的`File`类创建并写入这个VBScript文件。 3. 运行VBScript文件,通过`Runtime.getRuntime().exec()`方法调用`cscript`...
通过提供的标题"用JAVA读取硬盘序列号 -源码.zip"我们可以推断,这个压缩包包含了一段Java代码,用于实现这个功能。 首先,我们要理解硬盘序列号是存储在硬盘固件中的一个唯一的数字或字母组合,通常用来识别和验证...
return disk.SerialNumber print(get_disk_serial()) ``` 在Linux环境下,我们可以使用`hdparm`命令读取硬盘序列号,或者通过`udev`规则和`blkid`命令获取UUID。下面是一个使用bash脚本的例子: ```bash # 读取...
Console.WriteLine("Serial Number: " + disk["SerialNumber"]); } ``` 2. **Linux系统**:在Python中,可以使用`/sys/class/hdmi`目录下的文件来读取硬盘ID,如下: ```python import os with open('/sys/class/...
String serialNumber = result.getString("SerialNumber"); if (!serialNumber.isEmpty()) { return serialNumber; } } } catch (Exception e) { System.err.println("Error while querying WMI: " + e....
这个标识符可以是硬盘序列号(Serial Number)、硬盘型号(Model Number)或是硬盘的UUID(Universally Unique Identifier)。读取硬盘ID号是系统管理和硬件诊断的重要环节,尤其是在数据恢复、系统安装或设备追踪时...
JAVA读取硬盘序列号经典程序源码JAVA program to read hard disk serial number of the classical source
硬盘序列号可以通过读取硬盘的SMART数据来获取,这通常涉及到操作系统层面的磁盘I/O操作。在Java中,可以使用`java.io.File`类和`java.nio.file.Files`类进行文件I/O操作,但这些API不直接提供获取硬盘序列号的功能...
if (kernel32.GetVolumeInformationW(path, new WString(volumeNameBuffer), volumeNameBuffer.length, serialNumber, maxComponentLength, fileSystemFlags, null, 0)) { String serialNumberStr = Integer....
总结,读取SATA硬盘序列号涉及到Windows API的使用,通过C++代码实现,然后利用JNI技术与Java应用程序集成。这个过程需要对操作系统底层原理、C++编程以及Java JNI有深入理解。同时,为了确保跨平台兼容性,需要为...
System.out.println("硬盘序列号: " + serialNumber); } else { System.out.println("当前Java环境不支持获取硬盘序列号"); } } } ``` 这段代码首先获取了`OperatingSystemMXBean`的实例,然后通过`...
- 打开命令提示符,然后输入`wmic diskdrive get SerialNumber`。 - 这个命令会列出所有连接到系统的硬盘及其序列号。 3. **编程语言中的实现** 对于开发者来说,许多编程语言提供了API或者库来访问硬件信息。...
5. **获取硬盘序列号的本地实现**:在DLL中,可以使用Windows API如`CreateFile`、`DeviceIoControl`等函数来读取硬盘的SMART信息,从中提取序列号。也可以使用WMI查询`Win32_DiskDrive`类获取序列号。 6. **安全性...
在PowerBuilder中,通过编写自定义函数或者使用系统API调用来获取硬盘物理ID,例如Windows API的`GetVolumeInformation`函数,可以读取硬盘的物理信息。 接下来,我们讨论“DES加密”。DES(Data Encryption ...
String serialNumber = DiskIDUtil.getHardDriveSerialNumber(); ``` 这里的`getHardDriveSerialNumber()`方法应当返回当前计算机上某个或所有硬盘的序列号。 4. **处理结果**:获取到硬盘序列号后,可以根据...
wmic diskdrive get SerialNumber ``` 这个命令将列出所有连接到计算机的硬盘的序列号。此外,还可以使用第三方软件如`DiskId32`,这是一个小巧的实用程序,专门用于显示硬盘的详细信息,包括序列号。只需运行`...
当成功执行后,输出缓冲区会包含`STORAGE_DEVICE_DESCRIPTOR`结构,其中`SerialNumber`成员就是我们所需的硬盘序列号。 5. **处理结果**:从`STORAGE_DEVICE_DESCRIPTOR`结构体中提取序列号,并以适当的形式显示在...