wmi usage or PC info in java
I have been informed that Java doesn't have built-ins that get PC information, so I went looking around the net and found this. It does WMI calls in a Java program, as I can tell. Because this is a class, I am trying to use it. I think I am doing this correctly. I took from examples and tried to make it my own.
So, when I compile it, get 2 errors from where I have the class. It says that "jWMI WMIV=new jWMI();" cannot find symbol for "jWMI".
What am I doing wrong?
I have copied the .class and .java to the same folder as the wmitest.java. Does it go somewhere else or am I looking at this all wrong?
Last, question. Am I doing this all wrong?
jWMI – Query Windows WMI from Java | henryranch.net
Code :
//test the use of jWMI class call
import javax.swing.JOptionPane;
public class wmitest{
public static void main(String args[]){
jWMI WMIV=new jWMI();
String model = WMIV.getWMIValue("Select Model from Win32_ComputerSystem","Model");
JOptionPane.showMessageDialog(null,"This is the PC model__"+model);
}
}
Re: wmi usage or PC info in java
Quote:
cannot find symbol for "jWMI".
Where is the class jWMI defined? Its definition needs to be on the classpath so the compiler can find it.
(And also for the java program to execute )
You will also need an import statement if the class is in a package.
Re: wmi usage or PC info in java
Are you compiling from a command line?
Here's what I did with WindowsXP (Service Pack 3)
I copied jWMI.java to the directory from which I am going to compile.
I commented out the "package com.citumpe.ctpTools;" statement in jWMI.java since I am going commando (no package) for this experiment.
I changed your waittest.java file to handle an Exception (Since jWMI.java can throw one.)
I called it WMITest.java and it looks like this:
Code java:
//test the use of jWMI class call
// Zaphod_b
//
import javax.swing.JOptionPane;
import java.lang.Exception;
public class WMITest
{
public static void main(String [] args) {
try {
jWMI WMIV=new jWMI();
String model = WMIV.getWMIValue("Select Model from Win32_ComputerSystem","Model");
JOptionPane.showMessageDialog(null,"This is the PC model__" + model);
}
catch (Exception e) {
System.err.println("Caught exception: " + e.getMessage());
e.printStackTrace();
}
}
}
Then, from that directory I executed
javac WMITest.java
java WMITest
I got the Message Jpane, so I know it can work on my workstation.
Now, if you want to organize it as a package (probably in some IDE) just do the "usual" thing. Use the distribution version of jWMI.java with whatever package setup you prefer. (You will need to change the package statement in jWMI.java if your class directory tree is not com/citumpe/ctpTools.) Put files wherever you usually do. Do not copy the jWMI.class file from the distribution. You want to make sure jWMI.java is recompiled by your version compiler.
Cheers!
Z
Re: wmi usage or PC info in java
Quote:
Originally Posted by
Norm
Where is the class jWMI defined? Its definition needs to be on the classpath so the compiler can find it.
(And also for the java program to execute )
You will also need an import statement if the class is in a package.
I was able to fix the path on my PC, but I still don't understand classpath. I have been reading and reasearching all afternoon and most of the night, but haven't figured it out. But I think this this is what you are talking about.
javac =where I have the jWMI.class located wmitest.java
I have tried using the import statement but still get errors when I compile it. I will get a package doesn't exist error.
Re: wmi usage or PC info in java
Did you try to do as Z suggested in post#3?
Re: wmi usage or PC info in java
Zaphod_b
Thanks for the help. I was able to follow what you are telling me. I did get it to run, but I don't understand much about the try and catch stuff, so I will read about it some more.
So, when I want to put something like this in a program, I will need to add it as a package, because I eventually, want to make this all into a JAR so all, we are using is a single file.
Re: wmi usage or PC info in java
Yes and my head is still hurting from all the reading and trying things out. I really do appreciate the help. The book that I have, is old and doesn't always translate into what I am doing today. You can probably, see that I am doing a mix of old and new and trying to do thing way over my head, but I am really learning a lot.
Re: wmi usage or PC info in java
You don't need to put a class into a package. packages are a way to keep class names unique when there are a large number of classes used in a program and there is a chance of there being naming conflicts.
Re: wmi usage or PC info in java
Norm,
Thanks, some of this stuff is confusing.
By the way. . .I am on several Java forums, but I find this forums gives me REAL answers that I can use and not just read the tutorials.
Re: wmi usage or PC info in java
The tutorials are good places to read up on how stuff. Hopefully they are written by professionals.
If you have specific questions about them, copy the text here and ask your questions.