Java file my computer

Java file my computer

  • Introduction to Java
  • The complete History of Java Programming Language
  • C++ vs Java vs Python
  • How to Download and Install Java for 64 bit machine?
  • Setting up the environment in Java
  • How to Download and Install Eclipse on Windows?
  • JDK in Java
  • How JVM Works – JVM Architecture?
  • Differences between JDK, JRE and JVM
  • Just In Time Compiler
  • Difference between JIT and JVM in Java
  • Difference between Byte Code and Machine Code
  • How is Java platform independent?
  • Decision Making in Java (if, if-else, switch, break, continue, jump)
  • Java if statement with Examples
  • Java if-else
  • Java if-else-if ladder with Examples
  • Loops in Java
  • For Loop in Java
  • Java while loop with Examples
  • Java do-while loop with Examples
  • For-each loop in Java
  • Continue Statement in Java
  • Break statement in Java
  • Usage of Break keyword in Java
  • return keyword in Java
  • Object Oriented Programming (OOPs) Concept in Java
  • Why Java is not a purely Object-Oriented Language?
  • Classes and Objects in Java
  • Naming Conventions in Java
  • Java Methods
  • Access Modifiers in Java
  • Java Constructors
  • Four Main Object Oriented Programming Concepts of Java
  • Inheritance in Java
  • Abstraction in Java
  • Encapsulation in Java
  • Polymorphism in Java
  • Interfaces in Java
  • ‘this’ reference in Java

Источник

Get Hardware information in Java application

Follow us on our fanpages to receive notifications every time there are new articles. Facebook Twitter

Читайте также:  Выровнять изображение в html страницу

1- Java API to retrieve computer hardware information?

Sometimes you need to use Java to get information of computer hardware, including Serial Number of the mainboard, serial of hard drive, CPU, .

Unfortunately, Java has no such API, or may be there, but it was not released for free for programmers. However, on Windows you can obtain this information by executing the VB script.

2- Get hardware info using vbscript file

 Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select Name,UUID,Vendor,Version from Win32_ComputerSystemProduct") For Each objItem in colItems Wscript.Echo objItem.Name Wscript.Echo objItem.UUID Wscript.Echo objItem.Vendor Wscript.Echo objItem.Version Next 

In which Win32_ComputerSystemProduct is a class of Visual Basic, the properties of this class:

Properties
string Caption
string Description
string IdentifyingNumber
string Name
string SKUNumber
string UUID
string Vendor
string Version
 Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystemProduct") For Each objItem in colItems Wscript.Echo objItem.Caption Wscript.Echo objItem.Description Wscript.Echo objItem.IdentifyingNumber Wscript.Echo objItem.Name Wscript.Echo objItem.SKUNumber Wscript.Echo objItem.UUID Wscript.Echo objItem.Vendor Wscript.Echo objItem.Version Next 
Property Value (My Computer)
Caption Computer System Product
Description Computer System Product
IdentifyingNumber 3F027935U
Name Salellite S75B
SKUNumber null
UUID B09366C5-F0C7-E411-98E4-008CFA8C26DF
Vendor TOSHIBA
Version PSPPJU-07U051

3- Use Java to get computer hardware information

OK, above you know how to use vb script to retrieve the computer hardware information. Now you need to use the Java to execute vb script files and get the value returned.

 package org.o7planning.hardwareinfo; public class MyUtility < public static String makeVbScript(String vbClassName, String[] propNames) < StringBuilder sb = new StringBuilder(); for (int i = 0; i < propNames.length; i++) < if (i < propNames.length - 1) < sb.append(propNames[i]).append(","); >else < sb.append(propNames[i]); >> String colNameString = sb.toString(); sb.setLength(0); sb.append("Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")").append("\n"); sb.append("Set colItems = objWMIService.ExecQuery _ ").append("\n"); sb.append("(\"Select ").append(colNameString).append(" from ").append(vbClassName).append("\") ").append("\n"); sb.append("For Each objItem in colItems ").append("\n"); for (String propName : propNames) < sb.append(" Wscript.Echo objItem.").append(propName).append("\n"); >sb.append("Next ").append("\n"); return sb.toString(); > > 
 package org.o7planning.hardwareinfo; import java.io.BufferedReader; import java.io.File; import java.io.FileWriter; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; public class GetHardwareInfo < public static void printComputerSystemProductInfo() < String vbClassName = "Win32_ComputerSystemProduct"; String[] propNames = new String[] < "Name", "UUID", "Vendor", "Version" >; String vbScript = MyUtility.makeVbScript(vbClassName, propNames); System.out.println("----------------------------------------"); System.out.println(vbScript); System.out.println("----------------------------------------"); try < // Create temporary file. File file = File.createTempFile("vbsfile", ".vbs"); System.out.println("Create File: " + file.getAbsolutePath()); System.out.println("------"); // Write script content to file. FileWriter fw = new FileWriter(file); fw.write(vbScript); fw.close(); // Execute the file. Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath()); // Create Input stream to read data returned after execute vb script file. BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); Mapmap = new HashMap(); String line; int i = 0; while ((line = input.readLine()) != null) < if (i >= propNames.length) < break; >String key = propNames[i]; map.put(key, line); i++; > input.close(); // for (String propName : propNames) < System.out.println(propName + " : " + map.get(propName)); >> catch (Exception e) < e.printStackTrace(); >> public static void main(String[] args) < printComputerSystemProductInfo(); >> 

View more Tutorials:

These are online courses outside the o7planning website that we introduced, which may include free or discounted courses.

  • * * Bootstrap 4: Create a landing page
  • * * Getting Started with Amazon Web Services
  • Complete Python Web Course: Build 8 Python Web Apps
  • Learn Android Development From Scratch
  • 2D Game Development With HTML5 Canvas, JS — Tic Tac Toe Game
  • * * Java Database Connection: JDBC and MySQL
  • CSS Development (with CSS3!)
  • Superb jQuery Course — Become Certified jQuery Developer
  • Basic Concepts of Web Development, HTTP and Java Servlets
  • Node Program: From 0 to Hero with Nodejs and MongoDB
  • Java, JSP and JDBC programming guides for complete BEGINNER
  • Java Spring and Hibernate:create a crud application
  • Advance iOS 11 — To Go Even Further Beyond: Oil Lamp Bible
  • Building an Application with AngularJS
  • Kids Coding — Introduction to HTML, CSS and JavaScript!
  • Create Complete Web Applications easily with APEX 5
  • Oracle APEX Techniques
  • Flutter Web with Firebase Course
  • HTML5 CSS3 JQUERY Single Page Website Project from Scratch
  • The Complete React Native + Hooks Course [2020 Edition]
  • Python 3000: Tactical SQL Quick-Start
  • Build a Chatbot integrated Website using Bootstrap 4
  • Java Hibernate Framework:Learn Object/Relational Mapping ORM
  • Angular 2 Complete E-Commerce App Course — Java,Spring,MySQL
  • Ajax in JavaScript and JQuery, with PHP — Creating Chat App

Источник

Оцените статью