java查询软件_java查询已经安装的软件列表

本来是在 上看到一个c语言版本的,一直很纳闷怎么没有java版的p>

终于找到了一个用java版类似的,java通过调用系统API可以轻松获取已安装软件的详细信息。

经过大幅改进,效果相当不错,

原文章竟然找不到了,晕,等找到了把它地址放上来

上图:

0818b9ca8b590ca3270a3433284dd417.png

下载地址:

//附上源码

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import javax.swing.JFrame;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.JTextPane;

public class CheckSoftware {

private JFrame f = new JFrame(“已经安装的软件列表”);

private JTextPane textPane = new JTextPane();

private MyTable myTable=new MyTable();

public CheckSoftware() {

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()));

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()));

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()));

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()));

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()));

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()));

br.readLine();br.readLine();//去掉前两行无用信息

if((uninstallPathString=br.readLine())!=null){

uninstallPathString=uninstallPathString.replaceAll(“UninstallString REG_SZ “, “”);//去掉无用信息

}

String[] resultString=new String[4];

resultString[0]=nameString;

resultString[1]=versionString;

resultString[2]=publisherString;

resultString[3]=uninstallPathString;

if(resultString[0]==null) resultString=null;//没有名字的不显示

return resultString;

}

public static void main(String[] args) {

new CheckSoftware();

}

//列表

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;

}

}

}

文章知识点与官方知识档案匹配,可进一步学习相关知识Java技能树首页概览93918 人正在系统学习中 相关资源:IP地址查询软件 IPaddress(IP地址查询软件) v3.0.0

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年1月8日
下一篇 2021年1月8日

相关推荐