Java获取系统安装软件列表
/**
* @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获取系统安装软件列表的更多相关文章
- dotnet 通过 WMI 获取系统安装软件
本文告诉大家如何通过 WMI 获取系统安装的软件,这个方法不能获取全部的软件 通过 Win32_Product 可以获取系统安装的软件 var mc = "Win32_Product&quo ...
- PowerShell 通过 WMI 获取系统安装软件
本文告诉大家如何通过 WMI 获取系统安装的软件 通过 Win32_Product 可以获取系统安装的软件 Get-WmiObject Win32_Product | Format-List Capt ...
- 2019-8-31-PowerShell-通过-WMI-获取系统安装软件
title author date CreateTime categories PowerShell 通过 WMI 获取系统安装软件 lindexi 2019-08-31 16:55:58 +0800 ...
- 2019-4-29-dotnet-通过-WMI-获取系统安装软件
title author date CreateTime categories dotnet 通过 WMI 获取系统安装软件 lindexi 2019-04-29 12:18:59 +0800 201 ...
- Pyqt 获取windows系统中已安装软件列表
开始之前的基础知识 1. 获取软件列表 在Python的标准库中,_winreg可以操作Windows的注册表.获取已经安装的软件列表一般是读去windows的注册表: SOFTWARE\Micros ...
- Java获取环境变量和系统属性
Java获取服务器环境变量和JVM系统变量 当程序中需要使用与操作系统相关的变量(例如:文件分隔符.换行符)时,Java提供了System类的静态方法getenv()和getProperty() ...
- Windows软件在Linux上的等价/替代/模仿软件列表 (抄一个)
Last update: 16.07.2003, 31.01.2005, 27.05.2005 您可在以下网站发现本列表最新版:http://www.linuxrsp.ru/win-lin-soft/ ...
- ubuntu系统安装软件方法
ubuntu系统安装软件方法 ubuntu下安装软件有三种方式,分别为在线安装apt-get方式,软件商店安装方式和 1. 软件商店安装方式 这种方式对经常使用windows系统的同学来说最为简单,因 ...
- 【java 获取数据库信息】获取MySQL或其他数据库的详细信息
1.首先是 通过数据库获取数据表的详细列信息 package com.sxd.mysqlInfo.test; import java.sql.Connection; import java.sql.D ...
随机推荐
- map泛型 map不指定泛型 与 Map<Object,Object>的区别
map泛型 map不指定泛型 与 Map<Object,Object>的区别 private void viewDetail(){ Map map1 = new HashMap(); Ma ...
- UTF8、UTF16、UTF16-LE、UTF16-BE、UTF32都是些什么?
下述内容大部分引用自CSDN: Unicode 是 unicode.org 制定的编码标准,目前得到了绝大部分操作系统和编程语言的支持.unicode.org 官方对 Unicode 的定义是:Uni ...
- Chrome插件在页面上直接绑定JavaScript事件提示Refused to execute inline event handler because it violates the following Co
Chrome插件问了安全是不提倡在页面上直接写JavaScript的,如果出现了这个提示,其实也没有什么,同样可以运行. 从Chrome Extenstion V2开始,不允许执行任何inline j ...
- oracle解决连接池不足
select count(*) from v$process;----系统有多少连接数 select value from v$parameter where name = 'processe ...
- sqlserver 获取系统用户表结构信息
SELECT (case when a.colorder=1 then d.name else null end) 表名, a.colorder 字段序号,a.name 字段名, (case when ...
- 总结对Docker这个东西的想法
记得一开始的时候,还只能在一些网站上看到关于Docker零星的一些消息,之后的不久,有关Docker消息就遍布网络. 是什么因素让Docker火起来的? 或者说什么原因促使大家都对Docker感兴趣并 ...
- virtualbox 设置windows 于ubuntu虚拟机共享文件夹
会弹出错误, .. ..还是会有错误, modprobe -a vboxsf 之后就可以挂载成功了!!
- nginx+vue实例纪录
参考:http://www.cnblogs.com/wuac/p/6406843.html 新建工作目录vuepro,命令行之行命令:vue init webpack vue-test (项目默认的名 ...
- asyncio NetMQ 解决方案编译问题
程序集代码 (原) <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <VersionPrefix& ...
- 使RESTful Web服务更加实用的10个建议
提示:随着RESTful Web services的流行程度不断地上升,开发人员需要知道如何避免开发中的陷阱以及让开发出来的Web service达到自己能做到的最好程度. 过去的几年里,我们看到RE ...