digilive/windows-registry

一个小型库,用于访问和操作Windows注册表

v0.10.2 2020-06-12 13:09 UTC

This package is auto-updated.

Last update: 2024-09-16 23:57:04 UTC


README

GitHub release (latest by date including pre-releases) Codacy Badge GitHub license

一个小型库,用于访问和操作Microsoft Windows系统上的注册表。适用于需要在一个PHP应用程序中访问Windows注册表的一次性情况。

此库可以(并且已经被)用于生产代码,但在使用之前,请考虑阅读下面的免责声明

功能

  • 对注册表中的任何hive、键或值(您有权限访问)的读写访问
  • 自动在所有注册表值数据类型之间转换为PHP标量类型
  • 对值列表的懒加载迭代器和对键和子键的递归迭代器
  • 能够通过远程WMI(Windows管理规范)连接连接到远程计算机上的注册表(有关详细信息,请参阅Microsoft关于如何远程连接到WMI的文档)

要求

  • Microsoft Windows(Vista或更高版本)或Windows Server(Windows Server 2003或更高版本)
  • PHP com_dotnet 扩展

安装

使用Composer

> composer require digilive/windows-registry:~0.10

注意:此包替换了已弃用的包coderstephen/windows-registry v0.9.1。

文档

完整的API文档可在网上此处找到。

示例

以下是一个创建带有一些值的新注册表键然后删除它们的示例。

use Windows\Registry;

$hklm = Registry\Registry::connect()->getLocalMachine();
$keyPath = 'Software\\MyKey\\MySubKey';

// create a new key
try
{
    $mySubKey = $hklm->createSubKey($keyPath);
}
catch (Registry\Exception $e)
{
    print "Key '{$keyPath}' not created" . PHP_EOL;
}

// create a new value
$mySubKey->setValue('Example DWORD Value', 250, Registry\RegistryKey::TYPE_DWORD);

// delete the new value
$mySubKey->deleteValue('Example DWORD Value');

// delete the new key
try
{
    $hklm->deleteSubKey($keyPath);
}
catch (Registry\Exception $e)
{
    print "Key '{$keyPath}' not deleted" . PHP_EOL;
}

您还可以使用内置迭代器遍历子键和值

foreach ($key->getSubKeyIterator() as $name => $subKey)
{
    print $subKey->getQualifiedName() . PHP_EOL;
}

foreach ($key->getValueIterator() as $name => $value)
{
    printf("%s: %s\r\n", $name, $value);
}

免责声明

玩弄Windows注册表可能会有危险;Microsoft有大量关于它如何破坏您的安装的警告。不仅访问注册表时应该小心,此库也不保证100%安全且无错误。请谨慎使用,并在可能的情况下在虚拟机中测试您的代码。我们不承担由此库造成的任何损害的责任。有关详细信息,请参阅许可证