[英]How to get the list of installed applications on Windows 10 from Java
I'm trying to get a list of all applications installed in windows 10 from my Java program.我正在尝试从我的 Java 程序中获取 Windows 10 中安装的所有应用程序的列表。 I have tried the following:
我尝试了以下方法:
Runtime.getRuntime().exec("Get-WmiObject -class Win32_Product | Select-Object -Property Name");
and I get:我得到:
Cannot run program "Get-WmiObject": CreateProcess error=2
I tried too:我也试过:
Process p = Runtime.getRuntime().exec("Get-ItemProperty HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize");
With similar result.结果相似。
Finally, I tried to use the library "win32" but it only returns the name of some of the programs installed.最后,我尝试使用库“win32”,但它只返回一些已安装程序的名称。
I need the same result that I get when execute in powershell the following command:我需要与在 powershell 中执行以下命令时得到的结果相同的结果:
Get-ItemProperty HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* |
Get-ItemProperty HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
选择对象显示名称、显示版本、发布者、安装日期 | Format-Table –AutoSize
Format-Table –AutoSize
I had been looking for other questions in stackoverflow but none of them give me a solution.我一直在 stackoverflow 中寻找其他问题,但没有一个给我解决方案。 I need to search in every disk unit (and not only in C:).
我需要在每个磁盘单元中进行搜索(而不仅仅是在 C: 中)。 Someone can tell me a possible solution?
有人可以告诉我一个可能的解决方案吗?
Thanks.谢谢。
You can't run PowerShell commands directly, you have to launch them through the PowerShell process:你不能直接运行 PowerShell 命令,你必须通过 PowerShell 进程来启动它们:
powershell -command "PowerShell commands with parameters"
So change your exec call like this:所以像这样改变你的 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.