【问题标题】:How to get the list of installed applications on Windows 10 from Java如何从 Java 获取 Windows 10 上已安装应用程序的列表
【发布时间】:2018-02-07 19:53:56
【问题描述】:

我正在尝试从我的 Java 程序中获取 Windows 10 中安装的所有应用程序的列表。 我尝试了以下方法:

 Runtime.getRuntime().exec("Get-WmiObject -class Win32_Product | Select-Object -Property Name");

我得到:

Cannot run program "Get-WmiObject": CreateProcess error=2

我也试过了:

Process p = Runtime.getRuntime().exec("Get-ItemProperty HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize");

结果相似。

最后,我尝试使用库“win32”,但它只返回一些已安装程序的名称。

我需要的结果与在 powershell 中执行以下命令时得到的结果相同:

Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |选择对象 DisplayName、DisplayVersion、Publisher、InstallDate | Format-Table –AutoSize

我一直在寻找 stackoverflow 中的其他问题,但没有一个能给我解决方案。我需要在每个磁盘单元中搜索(而不仅仅是在 C: 中)。谁能告诉我一个可能的解决方案?

谢谢。

【问题讨论】:

    标签: java windows winapi registry winreg


    【解决方案1】:

    您不能直接运行 PowerShell 命令,您必须通过 PowerShell 进程启动它们:

    powershell -command "PowerShell commands with parameters"
    

    所以像这样改变你的 exec 调用:

    Process p = Runtime.getRuntime().exec("powershell -command \"Get-ItemProperty HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize\"");
    

    【讨论】:

      猜你喜欢
      • 2015-11-19
      • 1970-01-01
      • 2016-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多