我正试图从我的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中执行时得到的结果相同,下面的命令如下:
获取-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* \Select,DisplayVersion,Publisher,InstallDate Format-Table -AutoSize
我一直在寻找堆叠溢出的其他问题,但它们都没有给我一个解决方案。我需要搜索每个磁盘单元(而不仅仅是在C:中)。有人能告诉我一个可能的解决方案吗?
谢谢。
发布于 2018-02-07 20:59:22
不能直接运行PowerShell命令,必须通过PowerShell进程启动它们:
powershell -command "PowerShell commands with parameters"
因此,请按以下方式更改您的主管电话:
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\"");
https://stackoverflow.com/questions/48672200
复制相似问题