跪求Java Se 获取U盘唯一序列号Sn 的代码?

cz12980 2017-03-02 03:32:03
跪求Java Se 获取U盘唯一序列号Sn 的代码 或者 相关帖子链接。

感谢感谢。

以下是我通过检测工具检测得到的序列号。我希望能够通过java 写一个获取u盘序列号的代码。

...全文
318 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Hansy Chen 2017-03-07
  • 打赏
  • 举报
回复
你这个问题解决了吗,同求!
cz12980 2017-03-02
  • 打赏
  • 举报
回复
引用 1 楼 qq_30831935 的回复:
http://blog.csdn.net/liuwei063608/article/details/14135525 没测试帮转
感谢,不过这个作者写的是错误的。读出来的序列号有问题。

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;

/**
 * 遍历硬盘的信息
 * 
 * @author lilizhao
 *
 */
public class HardDiskInfo {
	public static void main(String[] args) {
		String s=getSerialNumber("H");
		System.out.println(s);
	}



/**
 *  Description:得到U盘序列号
 *  @author liuwei  DateTime 2013-11-4 下午6:05:56
 *  @param drive
 *  @return
 */
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();
  }
}
输出结果是:-690278735 结果是错误的。
鱿鱼ing 2017-03-02
  • 打赏
  • 举报
回复
http://blog.csdn.net/liuwei063608/article/details/14135525 没测试帮转

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧