PHP Classes


Recommend this page to a friend!
  Classes of DigiLive   PHP Access Windows Registry Access   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Access Windows Registry Access
Access and manipulate the Windows registry values
Author: By
Last change:
Date: 1 year ago
Size: 3,488 bytes


Class file image Download

Windows Registry Wrapper

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

A small library for accessing and manipulating the Registry on Microsoft Windows systems. For that one time you need to access the Windows Registry in a PHP application.

This library can be (and has been) used in production code, but please consider reading the disclaimer below before using.


  • Read and write access to any hive, key, or value in the registry (that you have permissions to)
  • Automatic conversion between all registry value data types to PHP scalar types
  • Lazy-loaded iterators over lists of values and recursive iterators over keys and subKeys
  • Ability to connect to registries on remote computers using a remote WMI (Windows Management Instrumentation) connection (see Microsoft's docs on how to connect to WMI remotely for details)


  • Microsoft Windows (Vista or newer) or Windows Server (Windows Server 2003 or newer)
  • PHP com_dotnet extension


Use Composer:

> composer require digilive/windows-registry:~0.10

Note: This package replaces package coderstephen/windows-registry v0.9.1 which has been abandoned.


Full API documentation is available online here.


Below is an example of creating a new registry key with some values and then deleting them.

use Windows\Registry;

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

// create a new key
    $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
catch (Registry\Exception $e)
    print "Key '{$keyPath}' not deleted" . PHP_EOL;

You can also iterate over subKeys and values using built-in iterators:

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

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


Messing with the Windows Registry can be dangerous; Microsoft has plenty of warnings about how it can destroy your installation. Not only should you be careful when accessing the Registry, this library is not guaranteed to be 100% safe to use and free of bugs. Use discretion, and test your code in a virtual machine if possible. We are not liable for any damages caused by this library. See the license for details.