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

时间:2016-09-27 20:32:35

标签: php powershell key registry wsh

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

我知道它如何与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“用于阅读

3 个答案:

答案 0 :(得分:0)

这可以解决您的问题:

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

echo "result: " . $data;

您做得正确,但您在当前所选文件夹中查找键/值,只需添加一个尾部斜杠即可获取子文件夹。

如果你检查注册表,那么&#34;卸载&#34;下面没有按键。文件夹,但必须有子文件夹。

答案 1 :(得分:0)

在PowerShell中,您可以像一样读取注册表项
Get-ItemProperty "hklm:\software\microsoft\windows\currentversion\uninstall\windows media player"

答案 2 :(得分:0)

这是一个允许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脚本的整个生命周期内都会维护该环境。