Java Program to Get CPU Serial Number for Windows Machine
CPU Serial Number (or Processor Serial Number) is a software-readable unique serial number that Intel has stamped into its Pentium 3 microprocessor. Intel offers this as a feature that can be optionally used to provide certain network management and e-commerce benefits. Basically, it lets a program identify individual PCs.
We can get the CPU Serial number of a Windows machine in 2 ways:
- By running the command on Windows PowerShell.
- Using FileWriter class in java
Way 1: Running PowerShell command
It is a similar way to what we say running commands on terminals on Mac. For windows, it’s CMD for which we do have a one-liner pred-defined command below. You simply need to write it as ities or copy the same from here which is given below as follows:
WMIC BIOS GET SERIALNUMBER
This pop-up window will appear letting us revealing the CPU serial number for the windows machine.
Way 2: Using FileWriter class
Java FileWriter class of java.io package is used to write data in character form to file.
- This class inherits from OutputStreamWriter class which in turn inherits from the Writer class.
- The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream.
- FileWriter is meant for writing streams of characters. For writing streams of raw bytes, consider using a FileOutputStream.
- FileWriter creates the output file if it is not present already.
Below is the hard-coded output when run on a Windows machine with the help of FileWriter class.
Note: In addition to this if these programs are windows specific and should not be run on other operating systems. Approach 1 will not work and for approach 2 that is the above approach been laid via FileWriter class if, on Mac the output is as follows. It is because ‘cscript’ cant be run on the terminal.