Bearsampp 2026.5.5
Loading...
Searching...
No Matches
Registry Class Reference

Public Member Functions

 __construct ()
 deleteValue ($key, $subkey, $entry)
 exists ($key, $subkey, $entry=null)
 getLatestError ()
 getValue ($key, $subkey, $entry=null)
 setExpandStringValue ($key, $subkey, $entry, $value)
 setStringValue ($key, $subkey, $entry, $value)

Data Fields

const APP_BINS_REG_ENTRY = 'BEARSAMPP_BINS'
const APP_PATH_REG_ENTRY = 'BEARSAMPP_PATH'
const END_PROCESS_STR = 'FINISHED!'
const ENV_KEY = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
const HKEY_CLASSES_ROOT = 'HKCR'
const HKEY_CURRENT_USER = 'HKCU'
const HKEY_LOCAL_MACHINE = 'HKLM'
const HKEY_USERS = 'HKEY_USERS'
const PROCESSOR_REG_ENTRY = 'Identifier'
const PROCESSOR_REG_SUBKEY = 'HARDWARE\DESCRIPTION\System\CentralProcessor\0'
const REG_BINARY = 'REG_BINARY'
const REG_DWORD = 'REG_DWORD'
const REG_ERROR_ENTRY = 'REG_ERROR_ENTRY'
const REG_ERROR_SET = 'REG_ERROR_SET'
const REG_EXPAND_SZ = 'REG_EXPAND_SZ'
const REG_MULTI_SZ = 'REG_MULTI_SZ'
const REG_NO_ERROR = 'REG_NO_ERROR'
const REG_SZ = 'REG_SZ'
const SYSPATH_REG_ENTRY = 'Path'

Private Member Functions

 setValue ($key, $subkey, $entry, $value, $type)
 writeLog ($log)

Private Attributes

 $latestError

Detailed Description

Class Registry

This class provides methods to interact with the Windows Registry using COM. It includes functionalities to check the existence of registry keys, get and set values, and delete registry entries. The class also logs operations and errors.

Definition at line 17 of file class.registry.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Registry constructor. Initializes the Registry class and logs the initialization.

Definition at line 57 of file class.registry.php.

58 {
59 Log::initClass($this);
60 $this->latestError = null;
61 }
static initClass($classInstance)

References Log\initClass().

Member Function Documentation

◆ deleteValue()

deleteValue ( $key,
$subkey,
$entry )

Deletes a registry entry.

Parameters
string$keyThe root key (e.g., HKEY_LOCAL_MACHINE).
string$subkeyThe subkey path.
string$entryThe entry name.
Returns
bool True if the entry was deleted successfully, false otherwise.

Definition at line 161 of file class.registry.php.

162 {
163 $this->writeLog('delete');
164 return $this->setValue($key, $subkey, $entry, null, 'DeleteValue');
165 }
setValue($key, $subkey, $entry, $value, $type)

References setValue(), and writeLog().

◆ exists()

exists ( $key,
$subkey,
$entry = null )

Checks if a registry key or entry exists. Now uses Win32Native COM methods instead of VBScript.

Parameters
string$keyThe root key (e.g., HKEY_LOCAL_MACHINE).
string$subkeyThe subkey path.
string | null$entryThe entry name (optional).
Returns
bool True if the key or entry exists, false otherwise.

Definition at line 83 of file class.registry.php.

84 {
85 $this->writeLog('Exists ' . $key . '\\' . $subkey . '\\' . $entry);
86
87 // Use Win32Native COM implementation
88 $result = Win32Native::registryExists($key, $subkey, $entry);
89
90 $this->writeLog('-> result: ' . ($result ? '1' : '0'));
91
92 return $result;
93 }
$result
static registryExists($hive, $key, $value=null)

References $result, Win32Native\registryExists(), and writeLog().

◆ getLatestError()

getLatestError ( )

Retrieves the latest error message.

Returns
string|null The latest error message, or null if no error occurred.

Definition at line 236 of file class.registry.php.

237 {
238 return $this->latestError;
239 }

References $latestError.

◆ getValue()

getValue ( $key,
$subkey,
$entry = null )

Retrieves the value of a registry entry. Now uses Win32Native COM methods instead of VBScript.

Parameters
string$keyThe root key (e.g., HKEY_LOCAL_MACHINE).
string$subkeyThe subkey path.
string | null$entryThe entry name (optional).
Returns
mixed The value of the registry entry, or false on error.

Definition at line 104 of file class.registry.php.

105 {
106 global $bearsamppLang;
107
108 $this->latestError = null;
109
110 $this->writeLog('GetValue ' . $key . '\\' . $subkey . '\\' . $entry);
111
112 // Use Win32Native COM implementation
113 $result = Win32Native::registryGetValue($key, $subkey, $entry);
114
115 $this->writeLog('-> result: ' . $result);
116
117 if ($result === null) {
118 $this->latestError = $bearsamppLang->getValue(Lang::ERROR) . ' Registry value not found';
119 return false;
120 }
121
122 return $result;
123 }
global $bearsamppLang
const ERROR
static registryGetValue($hive, $key, $value='')

References $bearsamppLang, $result, Lang\ERROR, Win32Native\registryGetValue(), and writeLog().

◆ setExpandStringValue()

setExpandStringValue ( $key,
$subkey,
$entry,
$value )

Sets an expanded string value in the registry.

Parameters
string$keyThe root key (e.g., HKEY_LOCAL_MACHINE).
string$subkeyThe subkey path.
string$entryThe entry name.
string$valueThe value to set.
Returns
bool True if the value was set successfully, false otherwise.

Definition at line 148 of file class.registry.php.

149 {
150 return $this->setValue($key, $subkey, $entry, $value, 'SetExpandedStringValue');
151 }

References setValue().

◆ setStringValue()

setStringValue ( $key,
$subkey,
$entry,
$value )

Sets a string value in the registry.

Parameters
string$keyThe root key (e.g., HKEY_LOCAL_MACHINE).
string$subkeyThe subkey path.
string$entryThe entry name.
string$valueThe value to set.
Returns
bool True if the value was set successfully, false otherwise.

Definition at line 134 of file class.registry.php.

135 {
136 return $this->setValue($key, $subkey, $entry, $value, 'SetStringValue');
137 }

References setValue().

◆ setValue()

setValue ( $key,
$subkey,
$entry,
$value,
$type )
private

Sets a value in the registry. Now uses Win32Native COM methods instead of VBScript.

Parameters
string$keyThe root key (e.g., HKEY_LOCAL_MACHINE).
string$subkeyThe subkey path.
string$entryThe entry name.
string | null$valueThe value to set (optional).
string$typeThe type of value to set (e.g., SetStringValue).
Returns
bool True if the value was set successfully, false otherwise.

Definition at line 178 of file class.registry.php.

179 {
180 global $bearsamppLang;
181
182 $this->latestError = null;
183
184 $this->writeLog('SetValue ' . $key . '\\' . $subkey . '\\' . $entry);
185 $this->writeLog('-> value: ' . $value);
186 $this->writeLog('-> type: ' . $type);
187
188 // Map the VBS type to Win32Native registry type
189 $regType = self::REG_SZ; // Default
190 if ($type == 'SetExpandedStringValue') {
191 $regType = self::REG_EXPAND_SZ;
192 } elseif ($type == 'SetStringValue') {
193 $regType = self::REG_SZ;
194 }
195
196 // Handle delete operations
197 if ($type == 'DeleteValue' && !empty($entry)) {
198 // Delete a value
199 $result = Win32Native::registryDeleteValue($key, $subkey, $entry);
200 } elseif ($type == 'DeleteValue' && empty($entry)) {
201 // Delete a key
203 } else {
204 // Set a value
205 $result = Win32Native::registrySetValue($key, $subkey, $entry, $value, $regType);
206 }
207
208 if ($subkey == self::ENV_KEY) {
210 }
211
212 $this->writeLog('-> result: ' . ($result ? 'success' : 'failed'));
213
214 if (!$result) {
215 $this->latestError = $bearsamppLang->getValue(Lang::ERROR) . ' Registry operation failed';
216 return false;
217 }
218
219 // Verify the value was set correctly (for set operations)
220 if ($type != 'DeleteValue' && !empty($value)) {
221 $verifyValue = Win32Native::registryGetValue($key, $subkey, $entry);
222 if ($verifyValue != $value) {
223 $this->latestError = sprintf($bearsamppLang->getValue(Lang::REGISTRY_SET_ERROR_TEXT), $value);
224 return false;
225 }
226 }
227
228 return true;
229 }
static refreshEnvVars()
const REGISTRY_SET_ERROR_TEXT
static registrySetValue($hive, $key, $value, $data, $type='REG_SZ')
static registryDeleteValue($hive, $key, $value)
static registryDeleteKey($hive, $key)

References $bearsamppLang, $result, Lang\ERROR, Batch\refreshEnvVars(), Lang\REGISTRY_SET_ERROR_TEXT, Win32Native\registryDeleteKey(), Win32Native\registryDeleteValue(), Win32Native\registryGetValue(), Win32Native\registrySetValue(), and writeLog().

Referenced by deleteValue(), setExpandStringValue(), and setStringValue().

◆ writeLog()

writeLog ( $log)
private

Writes a log entry.

Parameters
string$logThe log message to write.

Definition at line 68 of file class.registry.php.

69 {
70 global $bearsamppRoot;
71 Log::debug($log, $bearsamppRoot->getRegistryLogFilePath());
72 }
global $bearsamppRoot
static debug($data, $file=null)

References $bearsamppRoot, and Log\debug().

Referenced by deleteValue(), exists(), getValue(), and setValue().

Field Documentation

◆ $latestError

$latestError
private

Definition at line 51 of file class.registry.php.

Referenced by getLatestError().

◆ APP_BINS_REG_ENTRY

◆ APP_PATH_REG_ENTRY

const APP_PATH_REG_ENTRY = 'BEARSAMPP_PATH'

◆ END_PROCESS_STR

const END_PROCESS_STR = 'FINISHED!'

Definition at line 19 of file class.registry.php.

◆ ENV_KEY

const ENV_KEY = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'

◆ HKEY_CLASSES_ROOT

const HKEY_CLASSES_ROOT = 'HKCR'

Definition at line 21 of file class.registry.php.

◆ HKEY_CURRENT_USER

const HKEY_CURRENT_USER = 'HKCU'

Definition at line 22 of file class.registry.php.

◆ HKEY_LOCAL_MACHINE

◆ HKEY_USERS

const HKEY_USERS = 'HKEY_USERS'

Definition at line 24 of file class.registry.php.

◆ PROCESSOR_REG_ENTRY

const PROCESSOR_REG_ENTRY = 'Identifier'

Definition at line 49 of file class.registry.php.

Referenced by Util\getProcessorRegKey().

◆ PROCESSOR_REG_SUBKEY

const PROCESSOR_REG_SUBKEY = 'HARDWARE\DESCRIPTION\System\CentralProcessor\0'

Definition at line 48 of file class.registry.php.

Referenced by Util\getProcessorRegKey().

◆ REG_BINARY

const REG_BINARY = 'REG_BINARY'

Definition at line 28 of file class.registry.php.

◆ REG_DWORD

const REG_DWORD = 'REG_DWORD'

Definition at line 29 of file class.registry.php.

◆ REG_ERROR_ENTRY

const REG_ERROR_ENTRY = 'REG_ERROR_ENTRY'

Definition at line 32 of file class.registry.php.

◆ REG_ERROR_SET

const REG_ERROR_SET = 'REG_ERROR_SET'

Definition at line 33 of file class.registry.php.

◆ REG_EXPAND_SZ

const REG_EXPAND_SZ = 'REG_EXPAND_SZ'

Definition at line 27 of file class.registry.php.

◆ REG_MULTI_SZ

const REG_MULTI_SZ = 'REG_MULTI_SZ'

Definition at line 30 of file class.registry.php.

◆ REG_NO_ERROR

const REG_NO_ERROR = 'REG_NO_ERROR'

Definition at line 34 of file class.registry.php.

◆ REG_SZ

const REG_SZ = 'REG_SZ'

Definition at line 26 of file class.registry.php.

◆ SYSPATH_REG_ENTRY

const SYSPATH_REG_ENTRY = 'Path'

The documentation for this class was generated from the following file: