/**
* @author <a href="mailto:foohsinglong@gmail.com">kevin.long</a>
* @description Java获取系统软件安装列表,代码核心来自网上,主要通过Runtime实现,
* 用JNI也行,解决乱码问题
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset; import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextPane; public class SystemSoftware {
private JFrame f = new JFrame("本系统已经安装的软件列表");
private JTextPane textPane = new JTextPane();
private MyTable myTable=new MyTable();
public static Charset charset = Charset.forName("GBK");
public SystemSoftware() {
f.setLocation(300, 200);
f.setSize(800,500);
JScrollPane jScrollPane = new JScrollPane(myTable.getTable());
f.add(jScrollPane);
f.setVisible(true);
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE); try {
check();
} catch (Exception e) {
e.printStackTrace();
}
} private void check() throws Exception {
textPane.setText("您已经安装的软件:");
Runtime runtime = Runtime.getRuntime();
Process process = null;
process = runtime
.exec("cmd /c reg query HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\");
BufferedReader in = new BufferedReader(new InputStreamReader(process
.getInputStream(),"GBK"));
String string = null;
while ((string = in.readLine()) != null) {
process = runtime.exec("cmd /c reg query " + string
+ " /v DisplayName");
BufferedReader name = new BufferedReader(new InputStreamReader(
process.getInputStream(),"GBK"));
String[] message = queryValue(string);
if(message!=null) myTable.addRow(message);
f.repaint();
}
in.close();
process.destroy(); } //具体查询每一个软件的详细信息
private String[] queryValue(String string) throws IOException {
String nameString = "";
String versionString = ""; String publisherString="";
String uninstallPathString = ""; Runtime runtime = Runtime.getRuntime();
Process process = null;
BufferedReader br = null; process = runtime.exec("cmd /c reg query " + string + " /v DisplayName");
br = new BufferedReader(new InputStreamReader(process
.getInputStream(),"GBK"));
br.readLine();br.readLine();//去掉前两行无用信息
if((nameString=br.readLine())!=null){
nameString=nameString.replaceAll("DisplayName REG_SZ ", ""); //去掉无用信息
} process = runtime.exec("cmd /c reg query " + string + " /v DisplayVersion");
br = new BufferedReader(new InputStreamReader(process
.getInputStream(),"GBK"));
br.readLine();br.readLine();//去掉前两行无用信息
if((versionString=br.readLine())!=null){
versionString=versionString.replaceAll("DisplayVersion REG_SZ ", ""); //去掉无用信息
} process = runtime.exec("cmd /c reg query " + string + " /v Publisher");
br = new BufferedReader(new InputStreamReader(process
.getInputStream(),"GBK"));
br.readLine();br.readLine();//去掉前两行无用信息
if((publisherString=br.readLine())!=null){
publisherString =publisherString.replaceAll("Publisher REG_SZ ", ""); //去掉无用信息
} process = runtime.exec("cmd /c reg query " + string + " /v UninstallString");
br = new BufferedReader(new InputStreamReader(process
.getInputStream(),"GBK"));
br.readLine();br.readLine();//去掉前两行无用信息
if((uninstallPathString=br.readLine())!=null){
uninstallPathString=uninstallPathString.replaceAll("UninstallString REG_SZ ", ""); //去掉无用信息
} String[] resultString=new String[4];
resultString[0]= nameString ;//== null ? null : new String(nameString.getBytes(),"GB-2312");
resultString[1]= versionString ;//== null ? null : new String(versionString.getBytes(),"GB-2312");
resultString[2]= publisherString ;//== null ? null : new String(publisherString.getBytes(),"GB-2312");
resultString[3]= uninstallPathString ;//== null ? null : new String(uninstallPathString.getBytes(),"GB-2312");
if(resultString[0]==null) resultString=null; //没有名字的不显示
return resultString;
} //列表
private class MyTable{
private JTable jTable;
private Object[][] data=new Object[100][4];
private Object[] colNames= { "软件名称","版本号","出版商","卸载路径"};
private int p=-1; public MyTable(){ } public void addRow(Object[] data){
p++;
if(p>=100) return ;
this.data[p]=data;
} public JTable getTable(){
jTable=new JTable(data,colNames);
return jTable;
} } public static void main(String[] args) {
new SystemSoftware();
}
}

Java获取系统安装软件列表的更多相关文章

  1. dotnet 通过 WMI 获取系统安装软件

    本文告诉大家如何通过 WMI 获取系统安装的软件,这个方法不能获取全部的软件 通过 Win32_Product 可以获取系统安装的软件 var mc = "Win32_Product&quo ...

  2. PowerShell 通过 WMI 获取系统安装软件

    本文告诉大家如何通过 WMI 获取系统安装的软件 通过 Win32_Product 可以获取系统安装的软件 Get-WmiObject Win32_Product | Format-List Capt ...

  3. 2019-8-31-PowerShell-通过-WMI-获取系统安装软件

    title author date CreateTime categories PowerShell 通过 WMI 获取系统安装软件 lindexi 2019-08-31 16:55:58 +0800 ...

  4. 2019-4-29-dotnet-通过-WMI-获取系统安装软件

    title author date CreateTime categories dotnet 通过 WMI 获取系统安装软件 lindexi 2019-04-29 12:18:59 +0800 201 ...

  5. Pyqt 获取windows系统中已安装软件列表

    开始之前的基础知识 1. 获取软件列表 在Python的标准库中,_winreg可以操作Windows的注册表.获取已经安装的软件列表一般是读去windows的注册表: SOFTWARE\Micros ...

  6. Java获取环境变量和系统属性

    Java获取服务器环境变量和JVM系统变量    当程序中需要使用与操作系统相关的变量(例如:文件分隔符.换行符)时,Java提供了System类的静态方法getenv()和getProperty() ...

  7. Windows软件在Linux上的等价/替代/模仿软件列表 (抄一个)

    Last update: 16.07.2003, 31.01.2005, 27.05.2005 您可在以下网站发现本列表最新版:http://www.linuxrsp.ru/win-lin-soft/ ...

  8. ubuntu系统安装软件方法

    ubuntu系统安装软件方法 ubuntu下安装软件有三种方式,分别为在线安装apt-get方式,软件商店安装方式和 1. 软件商店安装方式 这种方式对经常使用windows系统的同学来说最为简单,因 ...

  9. 【java 获取数据库信息】获取MySQL或其他数据库的详细信息

    1.首先是 通过数据库获取数据表的详细列信息 package com.sxd.mysqlInfo.test; import java.sql.Connection; import java.sql.D ...

随机推荐

  1. 找出分数最高的前两个学生 Exercise05_09

    import java.util.Scanner; /** * @author 冰樱梦 * 时间:2018年下半年 * 题目:找出分数最高的前两个学生 * */ public class Exerci ...

  2. iOS开发——MJExtension复杂数组用法

    最近在看MJExtension的Demo,发现了一个plist文件直接转数组模型的方法.以前研究过但是浅尝辄止没有解决,这几天有时间,好好看了看,找到了解决办法,与大家分享. 如果大家的项目中有这种嵌 ...

  3. mongodb_服务端安装及连接

    安装环境:Windows7  64位    附件内容: 1.mongodb Windows7 补丁:451413_intl_x64_zip.exe 2.mongodb Windows 安装程序:mon ...

  4. inline-block空隙总结

    如果inline-block,宽度都是50%会留有空隙,解决方法如下 1.标签之间不留空格 (1)直接不留空 <div></div><div></div> ...

  5. subprocess使用,进入到某个目录下执行shell命令

    subprocess是用来fork一个子进程的.这个子进程可以运行一个外部程序. 函数: subprocess.call() subprocess.check_output() subprocess. ...

  6. git如何打补丁?

    git cherry-pick 可以把某个分支的某几次提交合入到当前分支,只是在一台设备上操作. git format-patch 可以把某个分支的n次提交分别打成n个补丁,然后把这些补丁文件(比如0 ...

  7. iOS:使用集成的支付宝SDK的支付流程

    基本步骤: 1.先与支付宝签约,获得商户的ID(partner)和账号ID(seller),这一部分主要是又公司负责: 2.下载相应的公钥私钥文件,用来给签名进行加密: 3.下载支付宝集成的SDK,网 ...

  8. [转载]Oracle Merge的使用

    FROM: http://zhangqchang.blog.163.com/blog/static/464989732009219114653226/ 摘至网上的几个例子 一.************ ...

  9. JavaScript 数字与字符串 比较大小

    总结一下JS中经常遇到纯数字和各种各样的字符串进行比较: 纯数字之间的比较 alert(1<3);//true 数字字符串比较,会将其先转成数字 alert("1"<& ...

  10. OpenGL 资源汇编

    本文收集和汇总了 OpenGL 的文档.教程和在线书籍,供学习和开发者參考. OPENGL开发教程:http://www.linuxgraphics.cn/opengl/index.html Open ...