The example provides various information about computer hardware and software. As listed below:
1. OS Installation date & Time
2. OS Serial Number
3. Motherboard Serial Number
4. Processor ID
5. Computer Name
The program provides information as stream of data, It is your JOB how you will extract information from stream and utilize them?
Note:The program will work only on windows platform and on Windows XP or later OS.
ComputerInfo.java
1. OS Installation date & Time
2. OS Serial Number
3. Motherboard Serial Number
4. Processor ID
5. Computer Name
The program provides information as stream of data, It is your JOB how you will extract information from stream and utilize them?
Note:The program will work only on windows platform and on Windows XP or later OS.
ComputerInfo.java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class ComputerInfo { public static void main(String[] args) { try { String[][] commands = new String[][]{ {"CMD", "/C", "WMIC OS GET Installdate,SerialNumber"}, //OS Installation date & Time, OS Serial Number {"CMD", "/C", "WMIC BASEBOARD GET SerialNumber"}, // Motherboadrd Serial Number {"CMD", "/C", "WMIC CPU GET ProcessorId"}, // Processor ID {"CMD", "/C", "WMIC COMPUTERSYSTEM GET Name"}}; // Computer Name for (int i = 0; i < commands.length; i++) { String[] com = commands[i]; Process process = Runtime.getRuntime().exec(com); process.getOutputStream().close(); //Closing output stream of the process System.out.println(); String s = null; //Reading sucessful output of the command BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); while ((s = reader.readLine()) != null) { System.out.print(s); } // Reading error if any reader = new BufferedReader(new InputStreamReader(process.getErrorStream())); while ((s = reader.readLine()) != null) { System.out.print(s); } } } catch (IOException e) { e.printStackTrace(); //TODO: necessary exception handling } } }
Comments
Post a Comment
Is this content helpful? Leave appreciation, feedback, suggestions, issues anything.