Click here to Skip to main content
15,887,746 members
Articles / Programming Languages / PHP

Registry Key Handling Through PHP

Rate me:
Please Sign up or sign in to vote.
4.56/5 (8 votes)
10 Jul 2012CPOL1 min read 38.2K   5  
This article is basically helpfull in handling Registry Key through PHP code.
<?php

	//
	//Reading Registry entry.
	//
	$Wshshell= new COM('WScript.Shell');
	$data= $Wshshell->regRead('HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip\path');
	echo "Data--->".$data."<br/>";


	//
	//Function for writing to the the Registry.
	//
	function registry_write($folder, $key, $value, $type="REG_SZ")
	{
	  $WshShell = new COM("WScript.Shell");

	  $registry = "HKEY_LOCAL_MACHINE\\SOFTWARE\\" . $folder . "\\" . $key;
	  try{
			$result = $WshShell->RegWrite($registry, $value, $type);
			echo "Entry is Successfully written at:".$registry;echo "<br/>"; 
			return($result);
	  }
	  catch(Exception $e){
		echo "Some Exception in Registry writing".$e;echo "<br/>";
	  }

	  return false;
	}
	
	
	//
	//Function for deleting the entry from the registry.
	//
	function registry_delete($folder, $key, $value, $type="REG_SZ")
	{
		$WshShell = new COM("Wscript.shell");
		$registry = "HKEY_LOCAL_MACHINE\\SOFTWARE\\" . $folder . "\\" . $key;
		try{
		$result = $WshShell->RegDelete($registry);
		echo $key." is Successfully deleted from HKEY_LOCAL_MACHINE\\SOFTWARE\\" . $folder ; 
		return($result);
		}
		catch(Exception $e){
			echo "Some Exception with the code:<br/>".$e;
		}
		return false;
		
	}

	$folder = "7-ZIP";
	$key = "Mac";
	$value = "123";
	
	//
	//If you want to use the registry_write() function,than use that function.
	//If you want to use the registry_delete() function,than use that function.
	//
	
	
	//registry_write($folder,$key,$value);
	registry_delete($folder,$key,$value);
?>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
C-DAC Hyderabad
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions