java获取安装软件列表(64位和32位)

本文介绍了一种使用Java代码获取Windows系统中已安装软件列表的方法。该方法利用Runtime执行CMD命令,通过注册表查询获取软件名称、版本等信息,并通过JNI解决乱码问题。
package com.sbr.nsiimp.analysis.action;

/**
 * @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 java.util.ArrayList;
import java.util.List;

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 process1 = null;  
        //64位
        process = runtime.exec("cmd /c reg query HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\");  
        //32位
        process1 = runtime.exec("cmd /c reg query HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\");  
                                       //HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream(),"GBK"));  
        BufferedReader in1 = new BufferedReader(new InputStreamReader(process1.getInputStream(),"GBK"));  
        String string = null;  
        String s3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值