Exemple #1
0
 /**
  * Function writes a value to the registry
  * @param <string> $folder Folder to save the registry value in
  * @param <string> $key Key to write to the registry
  * @param <string> $value Value to write to the registry
  * @param <string> $type (optional) Type of registry that is being used
  * @return <boolean> Whether registry was successfully written to or not
  * @category Extra
  * <code>
  *  $result = Extra::writeRegistry('registry\\path', 'key', 'value');
  * </code>
  */
 function writeRegistry($folder, $key, $value, $type = 'REG_SZ')
 {
     try {
         $WshShell = new COM("WScript.Shell");
         $registry = "HKEY_LOCAL_MACHINE\\SOFTWARE\\" . $folder . "\\" . $key;
         $result = $WshShell->RegWrite($registry, $value, $type);
         echo "Entry is Successfully written at : " . $registry;
         return $result;
     } catch (Exception $err) {
         return $err->getMessage();
     }
     return FALSE;
 }
Exemple #2
0
function phpreg()
{
    $shell1 = new COM("wscript.shell") or die("require windows host");
    $action = isset($_POST['action']) ? $_POST['action'] : '';
    echo '<div class="actall"><h5>Windows注册表读写</h5></div>';
    print <<<END
<TR><form action="" method="post">   
<div class="actall"><TD WIDTH=100 VALIGN=TOP ALIGN=CENTER>   
路径:<input type="hidden" name="action" value="读取">   
<input type="text" name="rpath" value="{$rpath}" size="70">   
<input class="bt" type="submit" value="读取"></form><br></TD></TR></div>   
END;
    $rpath = isset($_POST['rpath']) ? $_POST['rpath'] : '';
    $rpath = str_replace("\\\\", "\\", $rpath);
    if ($action == "read") {
        $out = $shell1->RegRead($rpath);
        echo '<pre>' . var_dump($out) . '</pre>';
    }
    print <<<END
<TR><form action="" method="post">   
<div class="actall"><TD WIDTH=100 VALIGN=TOP ALIGN=CENTER>位置:<input type="text" name="wpath" value="{$wpath}" size="70"><BR><br> 
类型:<input type="text" name="wtype" value="{$wtype}" size="20"> 值:<input type="text" name="wvalue" value="{$wvalue}" size="30">
<input type="hidden" name="action" value="write"><input class="bt" type="submit" value="写入"></form></TD></TR></div>   
END;
    $wpath = isset($_POST['wpath']) ? $_POST['wpath'] : '';
    $wpath = str_replace("\\\\", "\\", $wpath);
    $wtype = isset($_POST['wtype']) ? $_POST['wtype'] : '';
    $wvalue = isset($_POST['wvalue']) ? $_POST['wvalue'] : '';
    if ($action == "write") {
        $shell1->RegWrite($wpath, $wvalue, $wtype);
    }
    print <<<END
<TR><form action="" method="post">   
<div class="actall"><TD WIDTH=100 VALIGN=TOP ALIGN=CENTER>  
位置:<input type="hidden" name="action" value="del">   
<input type="text" name="dpath" value="{$dpath}" size="70">   
<input class="bt" type="submit" value="删"></form></TD></TR></div>   
END;
    $dpath = isset($_POST['dpath']) ? $_POST['dpath'] : '';
    $dpath = str_replace("\\\\", "\\", $dpath);
    if ($action == "del") {
        $out = $shell1->RegDelete($dpath);
    }
}
Exemple #3
0
 public function write($key, $value, $type = "REG_EXPAND_SZ")
 {
     try {
         $result = $this->shell->RegWrite($key, $value, $type);
         return $result;
     } catch (Exception $e) {
         echo "Write Registry Key : {$key} error." . PHP_EOL;
         echo "Exception Code " . $e->getCode() . PHP_EOL;
         echo "Exception Message : " . $e->getMessage() . PHP_EOL;
     }
     return false;
 }