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

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

终于找到了一个用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;

}

}

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java函数速查,方便使用的Java类库查询手册 chm版,可查询以下四个包的所有类库内容:   Package com.ms.wfc.app   Application类   CharacterSet类   Clipboard类   DataFormats类   DataFormats.Formats类   DataObject类   IDataObject界面   IMessageFilter界面   Locale类   Locale.CalendarType类   Locale.DateFormatOrder类   Locale.Languages类   Locale.LeadingZeros类   Locale.MeasurementSystem类   Locale.NegativeNumberMode类   Locale.OptionalCalendarType类 Locale.PositiveCurrencyMode类   Locale.Sort类   Locale.SubLanguages类   Message类   MethodInvoker代理   Registry类   RegistryKey类   SendKeys类   SpecialFolder类   SystemInformation类   SystemInformation.ArrangeDirection类   SystemInformation.ArrangeStartingPosition类   ThreadExceptionDialog类   ThreadExceptionEvent类   ThreadExceptionEventHandler代理   Time类   Timer类   Version类   Window类   Package com.ms.wfc.data.ui   Column类   ColumnEditingEvent类   ColumnEditingEventHandler代理   ColumnEvent类   ColumnEventHandler代理   ColumnResizeEvent类   ColumnResizeEventHandler代理   ColumnUpdatingEvent类   ColumnUpdatingEventHandler代理   DataBinder类   DataBinding类   DataGrid类   DataNavigator类   DataSource类   EnterAction类   ErrorEvent类   ErrorEventHandler代理   GridLineStyle类   PositionChangeEvent类   PositionChangeEventHandler代理   Scrollbars类   TabAction类      Package com.ms.wfc.html   DhAlignment类   DhBaseContainer类   DhBorderInfo类   DhBorders类   DhBorderStyle类   DhBreak类   DhBrowser类   DhBulletedList类   DhButton类   DhCantAddElementException类   DhCantModifyElementException类   DhCell类   DhCheckBox类   DhComboBox类   DhComponentWrapper类   DhCursor类   DhDialogInfo类   DhDocument类   DhEdit类   DhElement类   DhElementExistsInDocumentException类   DhElementNotFoundException类   DhEnumeration类   DhEventInfo类   DhForm类   DhHorizontalRule类   DhHotSpot类   DhHotSpotShapes类   DhHTMLGenerator类   DhHyperlink类   DhImage类   DhInlineFrame类   DhInsertOptions类   DhJumpPoint类   DhLinkTarget类   DhListBox类   DhListType类   DhMargins类   DhMarginWidthI

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值