Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: wmi usage or PC info in java

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

    //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);
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: wmi usage or PC info in java

    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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default 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:
    //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
    Last edited by Zaphod_b; September 11th, 2012 at 01:21 PM.

  4. #4
    Junior Member
    Join Date
    Jul 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: wmi usage or PC info in java

    Quote Originally Posted by Norm View Post
    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.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: wmi usage or PC info in java

    Did you try to do as Z suggested in post#3?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Jul 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  7. #7
    Junior Member
    Join Date
    Jul 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Jul 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Problem with java program and CPU usage
    By Bahramudin in forum Java Theory & Questions
    Replies: 3
    Last Post: July 25th, 2012, 09:26 AM
  2. The problem with Java and CPU usage, need HELP
    By Bahramudin in forum Member Introductions
    Replies: 1
    Last Post: July 25th, 2012, 09:23 AM
  3. Java, getting info from the web??!
    By chuckie987 in forum Java Theory & Questions
    Replies: 1
    Last Post: January 26th, 2011, 05:36 AM
  4. Grabbing info from Java game
    By n0bekre in forum Java Theory & Questions
    Replies: 1
    Last Post: June 27th, 2010, 10:32 AM
  5. HashMap usage in Java
    By neo_2010 in forum Collections and Generics
    Replies: 2
    Last Post: September 18th, 2009, 02:12 AM