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 ...
随机推荐
- 排排看(p20)
public class paixu{public static void main(String[] args){int x=3;if(x>2){System.out.print(" ...
- 使用jmatio读写matlab数据文件
/** * Created by hfz on 2016/2/23. */ import com.jmatio.io.*; import com.jmatio.types.MLDouble; impo ...
- 【JVM】Myecplise自带的JVM大小调整,用于Junit等测试时使用
一般在使用Junit或者一个工具类的main方法执行时,在Myecplise中运行,并不会占用多大的堆空间.如果出现OutofMemory错误,调整MyEcplise自带的JVM大小. 在Myecpl ...
- php实现简单视图模板(视图引擎)
视图 视图,你所看见的部分. <?php echo 'hello, world'; 从简单开始理解 这就是个视图文件中的代码,没错就这么简单.视图,实际上是在 MVC 这种架构上提出的.MVC ...
- Android Http POST文件上传之-----RFC1867协议
RFC1867协议介绍 RFC1867协议主要是在HTTP协议的基础上为INPUT标签添加了file属性.同一时候限定了Form的method必须为POST,ENCTYPE必须为 ...
- linux服务器网络配置
一.配置linux服务器的网络 手动修改配置网卡文件 先检查网卡是否正常 lspci |grep Ether 与网卡相关的TCP/IP网络配置文件位置 /etc/sysconfig/network-s ...
- Android -- 多媒体播放之MediaPlayer使用内部实现简析
Android -- MediaPlayer内部实现简析 在之前的博客中,已经介绍了使用MediaPlayer时要注意的内容.如今,这里就通过一个MediaPlayer代码实例,来进一步分析Media ...
- ubuntu14.04 server 安装docker
安装docker服务 $ curl -sSL https://get.docker.com/ | sh $ ocker run hello-world 测试docker是否安装成功 ubuntu ...
- 在Docker中从头部署自己的Spark集群
由于自己的电脑配置普普通通,在VM虚拟机中搭建的集群规模也就是6个节点左右,再多就会卡的不行 碰巧接触了Docker这种轻量级的容器虚拟化技术,理论上在普通PC机上搭建的集群规模可以达到很高(具体能有 ...
- storm安装配置
1.修改主机名: vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=MASTER 2.修改IP: 先用ifconfig得到ip信息,将其复制 设置i ...