如何使用Java获取Windows上所有已安装应用程序的引用?

时间:2018-04-05 20:55:33

标签: java powershell search

我知道我可以运行这个PowerShell命令

"Get-ItemProperty HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Select-Object DisplayName"

我设法将输出存储在String ArrayList中。现在我有所有已安装的应用程序的名称,但不是我可以启动的实际引用。

static List<File> Applications = new ArrayList<File>();
public static void recSearch (String path) {
    File root = new File(path);
    File[] list = root.listFiles();

    if (list == null) return;

    for (File f : list) {
        if (f.isDirectory()) {
            recSearch(f.getAbsolutePath());
            if (f.getName().endsWith(".exe"))
            System.out.println("Dir:" + f.getAbsoluteFile());
        }
        else if (f.getName().endsWith(".exe") && f.canExecute()){
            Applications.add(f);
            System.out.println("File:" + f.getAbsoluteFile());
        }
    }
}

有了这个,我将每个.exe存储在一个文件列表中,不仅是每个应用程序,还包括每次安装,卸载等等。我可以从这个skript运行它们,但是战场4被称为bf4.exe并且要运行特定的应用程序,我必须知道每个name.exe而不仅仅是应用程序名称。

现在我想知道如何获取上面代码中的引用文件,但是对于每个已安装的应用程序(即来自PowerShell命令的应用程序)。

先谢谢你,请问我的问题是否不清楚,这是我第一次在这里提问:)

0 个答案:

没有答案