Results 1 to 5 of 5
- 03-02-2013, 06:52 AM #1
Member
- Join Date
- Mar 2013
- Posts
- 2
- Rep Power
- 0
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); } }
Last edited by keerthana.nivas; 03-02-2013 at 08:17 AM.
- 03-02-2013, 07:39 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
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.
- 03-02-2013, 08:16 AM #3
Member
- Join Date
- Mar 2013
- Posts
- 2
- Rep Power
- 0
- 03-02-2013, 10:25 AM #4
Re: cant get graph of cpu,memory,disk usage of system
What does your posted code have to do with your subject line?
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 03-02-2013, 10:27 AM #5
Similar Threads
-
Java total memory and memory usage increase when using mysql function?
By newbie14 in forum Advanced JavaReplies: 2Last Post: 08-20-2012, 07:38 PM -
Application Memory Usage...
By switch in forum AWT / SwingReplies: 1Last Post: 01-26-2012, 08:13 PM -
The mos memory and disk efficient way to serialize a part of an array of primitives?
By kreyszig in forum Advanced JavaReplies: 3Last Post: 10-15-2010, 04:03 PM -
Memory usage
By Moon_E in forum New To JavaReplies: 20Last Post: 07-09-2010, 11:53 PM -
JVM memory usage
By lardum in forum New To JavaReplies: 7Last Post: 06-26-2008, 04:30 AM
Bookmarks