PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of H. Poort   b3rtWindowsRegistry   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example
Class: b3rtWindowsRegistry
Read from and write to the Windows registry
Author: By
Last change: Made example accessible without user login
Date: 15 years ago
Size: 3,591 bytes
 

Contents

Class file image Download
<?php

require 'class.b3rtWindowsRegistry.php';

$windowsRegistry = new b3rtWindowsRegistry();

echo
"\n\n";
echo
"List some key names\n";
echo
"================================\n\n";

$keyNames = $windowsRegistry->GetSubKeys('HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion');
if (
$keyNames)
    for (
$i = 0, $cnt = count($keyNames); $i < $cnt; $i++)
        echo
$keyNames[$i] . ' * ';

echo
"\n\n";
echo
"List some value names\n";
echo
"================================\n\n";

$valueNames = $windowsRegistry->GetValueNames('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion');
if (
$valueNames)
    for (
$i = 0, $cnt = count($valueNames); $i < $cnt; $i++)
        echo
$valueNames[$i] . ' * ';

echo
"\n\n";
echo
"Read some values\n";
echo
"================================\n\n";

echo
$windowsRegistry->ReadValue('HKEY_CLASSES_ROOT\\.exe', '', TRUE) . "\n";
echo
$windowsRegistry->ReadValue('HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion', 'CommonFilesDir', TRUE) . "\n";
echo
$windowsRegistry->ReadValue('HKEY_CURRENT_USER\\Control Panel\\Mouse', 'DoubleClickSpeed', TRUE) . "\n";
echo
$windowsRegistry->ReadValue('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileAssociation', 'CutList', TRUE) . "\n";
echo
$windowsRegistry->ReadValue('HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer', 'ShellState', TRUE) . "\n";
echo
$windowsRegistry->ReadValue('HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion', 'ProgramFilesPath', TRUE) . "\n";

echo
"\n\n";
echo
"Check if some keys exist\n";
echo
"================================\n\n";

if (
$windowsRegistry->KeyExists('HKEY_LOCAL_MACHINE\\Software\\Microsoft'))
    echo
"Key exists\n";
if (
$windowsRegistry->KeyExists('HKEY_CURRENT_USER\\Software\\Microsoft'))
    echo
"Key exists\n";
if (!
$windowsRegistry->KeyExists('HKEY_LOCAL_MACHINE\\Software\\Micr0s0ft'))
    echo
"Key does not exist\n";

echo
"\n\n";
echo
"Write some values\n";
echo
"================================\n\n";

//if ($windowsRegistry->CreateKey('HKEY_CURRENT_USER\\Software\\FooBar Software'))
// echo "Created test key\n";
if ($windowsRegistry->WriteValue('HKEY_CURRENT_USER\\Software\\FooBar Software', '', 'FooBar Software'))
    echo
"Wrote default value\n";
if (
$windowsRegistry->WriteValue('HKEY_CURRENT_USER\\Software\\FooBar Software', 'foo1', 'bar'))
    echo
"Wrote string\n";
if (
$windowsRegistry->WriteValue('HKEY_CURRENT_USER\\Software\\FooBar Software', 'foo2', 1234))
//if ($windowsRegistry->WriteValue('HKEY_CURRENT_USER\\Software\\FooBar Software', 'foo2', '1234', b3rtWindowsRegistry::REG_DWORD))
   
echo "Wrote integer\n";
if (
$windowsRegistry->WriteValue('HKEY_CURRENT_USER\\Software\\FooBar Software', 'foo3', array('1', '2', '3', '4')))
    echo
"Wrote multi-string\n";
if (
$windowsRegistry->WriteValue('HKEY_CURRENT_USER\\Software\\FooBar Software', 'foo4', array(0x16, 0x32, 0x64, 0xC8)))
    echo
"Wrote binary\n";
if (
$windowsRegistry->WriteValue('HKEY_CURRENT_USER\\Software\\FooBar Software', 'foo5', '%SystemRoot%\\System32', b3rtWindowsRegistry::REG_EXPAND_SZ))
    echo
"Wrote expanded string\n";
if (
$windowsRegistry->CreateKey('HKEY_CURRENT_USER\\Software\\FooBar Software\\Subkey\\Subkey2'))
    echo
"Created subkeys\n";
if (
$windowsRegistry->DeleteValue('HKEY_CURRENT_USER\\Software\\FooBar Software', ''))
    echo
"Deleted default value\n";
if (
$windowsRegistry->DeleteKey('HKEY_CURRENT_USER\\Software\\FooBar Software', TRUE))
    echo
"Deleted test key\n";

unset(
$windowsRegistry);

?>