JAVA reads related information from the computer

Source: Internet
Author: User

Java Read Computer cup number

Read version number

Graphics

。。

。。。。。。。。

。。

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;/** * Get hardware information * @author LUOXF * */public class Hardwareutils {/*        * * GET motherboard serial number * @return */public static string Getmotherboardsn () {String result = "";            try {//create temporary files file = File.createtempfile ("Realhowto", ". vbs");            When the program ends, the call is different from the delete (the program starts the call relative to just making a declaration) File.deleteonexit ();             FileWriter FW = new FileWriter (file); String vbs = "Set objWMIService = GetObject (\" winmgmts:\\\\.\\root\\cimv2\ ") \ n" + "Set colitems = OBJWM Iservice.execquery _ \ n "+" (\ "SELECT * from win32_baseboard\") \ n "+" for each O  Bjitem 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 ();        }/** * Gets the CPU serial number * * @return */public static string Getcpuserial () {String result = "";                       try {//create temporary files 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 = OBJWM Iservice.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 = "no cpu_id is read";    } return Result.trim ();   }/** * Gets the hard drive serial number * * @param drives * Drive letter * @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.dr                    ives\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 ();        }/** * Get MAC Address */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 ("Motherboard SN:" + HARDWAREUTILS.GETMOTHERBOARDSN () +hardwareutils.getcpuserial ());//System.out.println    ("C-plate SN:" + HARDWAREUTILS.GETHARDDISKSN ("C"));//System.out.println ("MAC SN:" + Hardwareutils.getmac ()); }        }


JAVA reads related information from the computer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.