获取已安装程序的注册表项 php

Get the registry key of installed programs php

我想获取已安装程序的列表。

我知道它是如何与 powershell 一起工作的:Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize .

但我想要 php。现在我有了这个:

<?php
$Wshshell= new COM('WScript.Shell');
$data = $Wshshell->regRead('HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall');

?>

我收到此错误:来源: WshShell.RegRead
描述: 无法打开注册表项 "HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" 进行阅读

这可以解决您的问题:

$Wshshell = new COM('WScript.Shell');
$data = $Wshshell->regRead("HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\");

echo "result: " . $data;

您做对了,但是您在当前选定的文件夹中寻找 keys/values,只需添加尾部斜杠即可获取子文件夹。

如果检查注册表,“Uninstall”文件夹下没有项,但必须有子文件夹。

在 powershell 中,您可以像这样读取注册表项

Get-ItemProperty "hklm:\software\microsoft\windows\currentversion\uninstall\windows media player"

这是一个允许 PHP 获取真实 Powershell 并与之动态交互的项目。在这里获取:https://github.com/merlinthemagic/MTS

下载后您只需使用以下代码:

$shellObj    = \MTS\Factories::getDevices()->getLocalHost()->getShell('powershell');

$strCmd   = 'Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate';

$return1  = $shellObj->exeCmd($strCmd);

echo $return1;// list of all programs

您可以对 $shellObj 发出您喜欢的任何命令,环境在 PHP 脚本的整个生命周期内得到维护。