Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Post cant get graph of cpu,memory,disk usage of system

    Java Code:
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.InputStreamReader;
    import java.util.*;
    
    public class psk {
      private psk() {  }
    
      public static List<String> listRunningProcesses() {
        List<String> processList = new ArrayList<String>();
        try {
    
            File file = File.createTempFile("realhowto",".vbs");
            file.deleteOnExit();
            FileWriter fw = new java.io.FileWriter(file);
    
            String vbs = "Set WshShell = WScript.CreateObject(\"WScript.Shell\")\n"
                       + "Set locator = CreateObject(\"WbemScripting.SWbemLocator\")\n"
                       + "Set service = locator.ConnectServer()\n"
                       + "Set processes = service.ExecQuery _\n"
                       + " (\"select name from Win32_Process\")\n"
                       + "For Each process in processes\n"
                       + "wscript.echo process.Name \n"
                       + "Next\n"
                       + "Set WSHShell = Nothing\n";
    
            fw.write(vbs);
            fw.close();
            Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
            BufferedReader input =
                new BufferedReader
                  (new InputStreamReader(p.getInputStream()));
            String line;
            while ((line = input.readLine()) != null) {
                processList.add(line);
            }
            input.close();
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return processList;
      }
    
      public static void main(String[] args){
        List<String> processes = VBSUtils.listRunningProcesses();
        String result = "";
    
        Iterator<String> it = processes.iterator();
        int i = 0;
        while (it.hasNext()) {
           result += it.next() +"";
           i++;
           if (i==10) {
               result += "\n";
               i = 0;
           }
        }
        msgBox("Running processes :  \n\n"+ result);
      }
    
      public static void msgBox(String msg) {
        javax.swing.JOptionPane.showConfirmDialog((java.awt.Component)
           null, msg, "VBSUtils", javax.swing.JOptionPane.DEFAULT_OPTION);
      }
    }
    i can get process list but not the cpu,memory & disk usage in graph format pls help
    Last edited by keerthana.nivas; 03-02-2013 at 07:17 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: cant get graph of cpu,memory,disk usage of system

    Hi keerthana.nivas, welcome to the forums!

    I've added code tags to your post. What you do when you post code is put [code] at the start of the code and [/code] at the end. This will make the code readable when it appears here.

    It is also a good idea to be forthright when cross posting. This discussion has also been started at javaprogrammingforums.com. Posting links at each site to the others lets everyone follow the whole discussion. You should be aware that some people are reluctant to participate when something has been cross posted for fear of wasting their time on something that has been settled elsewhere. It can take a while for responses to turn up, especially in the weekend.

    This is really a VB question, and you might have more luck on a VB or Windows site.

  3. #3
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Post Re: cant get graph of cpu,memory,disk usage of system

    Quote Originally Posted by pbrockway2 View Post
    Hi keerthana.nivas, welcome to the forums!

    I've added code tags to your post. What you do when you post code is put [code] at the start of the code and [/code] at the end. This will make the code readable when it appears here.

    It is also a good idea to be forthright when cross posting. This discussion has also been started at javaprogrammingforums.com. Posting links at each site to the others lets everyone follow the whole discussion. You should be aware that some people are reluctant to participate when something has been cross posted for fear of wasting their time on something that has been settled elsewhere. It can take a while for responses to turn up, especially in the weekend.

    This is really a VB question, and you might have more luck on a VB or Windows site.
    sorry i wasnt knowing,
    i need this task in java coding not VB,if possible pls help

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,419
    Rep Power
    20

    Default Re: cant get graph of cpu,memory,disk usage of system

    What does your posted code have to do with your subject line?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,419
    Rep Power
    20

    Default Re: cant get graph of cpu,memory,disk usage of system

    Also, you should acknowledge the source of any and all code you copy from elsewhere on the net.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 2
    Last Post: 08-20-2012, 06:38 PM
  2. Application Memory Usage...
    By switch in forum AWT / Swing
    Replies: 1
    Last Post: 01-26-2012, 07:13 PM
  3. Replies: 3
    Last Post: 10-15-2010, 03:03 PM
  4. Memory usage
    By Moon_E in forum New To Java
    Replies: 20
    Last Post: 07-09-2010, 10:53 PM
  5. JVM memory usage
    By lardum in forum New To Java
    Replies: 7
    Last Post: 06-26-2008, 03:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •