139 public function getValue($key, $subkey, $entry =
null)
143 $basename =
'registryGetValue';
145 $this->latestError =
null;
147 $scriptContent =
'On Error Resume Next' . PHP_EOL;
148 $scriptContent .=
'Err.Clear' . PHP_EOL . PHP_EOL;
150 $scriptContent .=
'Dim objShell, objFso, objFile, outFile, entryValue' . PHP_EOL . PHP_EOL;
152 $scriptContent .=
'outFile = "' . $resultFile .
'"' . PHP_EOL;
153 $scriptContent .=
'Set objShell = WScript.CreateObject("WScript.Shell")' . PHP_EOL;
154 $scriptContent .=
'Set objFso = CreateObject("Scripting.FileSystemObject")' . PHP_EOL;
155 $scriptContent .=
'Set objFile = objFso.CreateTextFile(outFile, True)' . PHP_EOL . PHP_EOL;
157 $scriptContent .=
'entryValue = objShell.RegRead("' . $key .
'\\' . $subkey .
'\\' . $entry .
'")' . PHP_EOL;
158 $scriptContent .=
'If Err.Number <> 0 Then' . PHP_EOL;
159 $scriptContent .=
' objFile.Write "' . self::REG_ERROR_ENTRY .
'" & Err.Number & ": " & Err.Description' . PHP_EOL;
160 $scriptContent .=
'Else' . PHP_EOL;
161 $scriptContent .=
' objFile.Write entryValue' . PHP_EOL;
162 $scriptContent .=
'End If' . PHP_EOL;
163 $scriptContent .=
'objFile.Close' . PHP_EOL;
167 $this->
writeLog(
'GetValue ' . $key .
'\\' . $subkey .
'\\' . $entry);
229 private function setValue($key, $subkey, $entry, $value, $type)
233 $basename =
'registrySetValue';
235 $this->latestError =
null;
238 if ($key == self::HKEY_CLASSES_ROOT) {
240 } elseif ($key == self::HKEY_CURRENT_USER) {
242 } elseif ($key == self::HKEY_LOCAL_MACHINE) {
244 } elseif ($key == self::HKEY_LOCAL_MACHINE) {
248 $scriptContent =
'On Error Resume Next' . PHP_EOL;
249 $scriptContent .=
'Err.Clear' . PHP_EOL . PHP_EOL;
251 $scriptContent .=
'Const HKEY = ' . $key . PHP_EOL . PHP_EOL;
253 $scriptContent .=
'Dim objShell, objRegistry, objFso, objFile, outFile, entryValue, newValue' . PHP_EOL . PHP_EOL;
255 $scriptContent .=
'newValue = "' . (!empty($value) ? str_replace(
'"',
'""', $value) :
'') .
'"' . PHP_EOL;
256 $scriptContent .=
'outFile = "' . $resultFile .
'"' . PHP_EOL;
257 $scriptContent .=
'Set objShell = WScript.CreateObject("WScript.Shell")' . PHP_EOL;
258 $scriptContent .=
'Set objRegistry = GetObject("winmgmts://./root/default:StdRegProv")' . PHP_EOL;
259 $scriptContent .=
'Set objFso = CreateObject("Scripting.FileSystemObject")' . PHP_EOL;
260 $scriptContent .=
'Set objFile = objFso.CreateTextFile(outFile, True)' . PHP_EOL . PHP_EOL;
262 if (!empty($value)) {
263 $scriptContent .=
'objRegistry.' . $type .
' HKEY, "' . $subkey .
'", "' . $entry .
'", newValue' . PHP_EOL;
264 } elseif (!empty($entry)) {
265 $scriptContent .=
'objRegistry.' . $type .
' HKEY, "' . $subkey .
'", "' . $entry .
'"' . PHP_EOL;
267 $scriptContent .=
'objRegistry.' . $type .
' HKEY, "' . $subkey .
'"' . PHP_EOL;
269 $scriptContent .=
'If Err.Number <> 0 Then' . PHP_EOL;
270 $scriptContent .=
' objFile.Write "' . self::REG_ERROR_ENTRY .
'" & Err.Number & ": " & Err.Description' . PHP_EOL;
271 $scriptContent .=
'Else' . PHP_EOL;
272 if (!empty($value)) {
273 $scriptContent .=
' entryValue = objShell.RegRead("' . $strKey .
'\\' . $subkey .
'\\' . $entry .
'")' . PHP_EOL;
274 $scriptContent .=
' If entryValue = newValue Then' . PHP_EOL;
275 $scriptContent .=
' objFile.Write "' . self::REG_NO_ERROR .
'"' . PHP_EOL;
276 $scriptContent .=
' Else' . PHP_EOL;
277 $scriptContent .=
' objFile.Write "' . self::REG_ERROR_SET .
'" & newValue' . PHP_EOL;
278 $scriptContent .=
' End If' . PHP_EOL;
280 $scriptContent .=
' objFile.Write "' . self::REG_NO_ERROR .
'"' . PHP_EOL;
282 $scriptContent .=
'End If' . PHP_EOL;
283 $scriptContent .=
'objFile.Close' . PHP_EOL;
288 if ($subkey == self::ENV_KEY) {
292 $this->
writeLog(
'SetValue ' . $strKey .
'\\' . $subkey .
'\\' . $entry);
293 $this->
writeLog(
'-> value: ' . $value);