首页 文章

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

提问于
浏览
0

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

我知道它如何与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');

?>

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

3 回答

  • 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脚本的整个生命周期中都会维护该环境 .

  • 0

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

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

    这可以解决您的问题:

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

    你做得正确,但你在当前选择的文件夹中寻找键/值,只需添加一个尾部斜杠来获取子文件夹 .

    如果检查注册表,则“卸载”文件夹下没有任何键,但必须有子文件夹 .

相关问题