gpt4 book ai didi

java - 如何从 Java 获取 Windows 10 上已安装的应用程序列表

转载 作者:可可西里 更新时间:2023-11-01 10:32:24 27 4
gpt4 key购买 nike

我正在尝试从我的 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\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize

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

谢谢。

最佳答案

您不能直接运行 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\"");

关于java - 如何从 Java 获取 Windows 10 上已安装的应用程序列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48672200/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com