所以我想在应用程序打开时检查程序是否正在运行“join.me”。
这是下载的网站。
Process joinme = Runtime.getRuntime().exec("join.me");
这似乎不起作用。
有什么想法吗?
或者我想循环遍历一系列进程,以查看调用“join.me”进程的内容。
干杯。
答案 0 :(得分:3)
您需要使用Microsoft随附的OOTB tasklist.exe
实用程序,该实用程序位于C:\windows\system32\tasklist.exe
。以下一行:
Process p = Runtime.getRuntime().exec("tasklist.exe");
会执行它。然后,您可以使用Scanner
读取此字符串,直到它有下一行。以下代码为您提供了在系统上运行的正在运行的程序(前台应用程序和后台应用程序)的列表:
public static void main(String[] args) throws IOException {
Process process = Runtime.getRuntime().exec("tasklist.exe");
Scanner scanner = new Scanner(new InputStreamReader(process.getInputStream()));
while (scanner.hasNext()) {
System.out.println(scanner.nextLine());
}
scanner.close();
}