繁体   English   中英

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

[英]How to get the list of installed applications on Windows 10 from Java

我正在尝试从我的 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\\* | 选择对象显示名称、显示版本、发布者、安装日期 | 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\"");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM