/** SAMPLE CODE FOR wmiRegistryTools.js
*/

// include the library
eval(include("wmiNetworkTools.js"));

// here is our include function. This can be placed at the end of the script if you wish
function include(fileName) {
	var fso = new ActiveXObject("Scripting.FileSystemObject"); // create the file system object
	if( !fso.FileExists(fileName) ) { return -1; } // check for file existance and fail if no file
	var file = fso.OpenTextFile(fileName);
	var stream = file.ReadAll();
	file.Close();
	return stream;
}

// Now the real fun begins.

// registryToolsCreateKey()
registryToolsCreateKey(".", "HKCU", "test\\myKey");
registryToolsCreateKey(".", "HKCU", "test\\myKey\\subKeyOne");
registryToolsCreateKey(".", "HKCU", "test\\myKey\\subKeyTwo");
registryToolsCreateKey(".", "HKCU", "test\\myKey\\subKeyOne\\anotherChild");

// registryToolsWriteValue()
var binaryArray = new Array(); // create the binary values to be stored
var stringArray = new Array(); // string array
binaryArray[0] = 00;
binaryArray[1] = 01;
binaryArray[2] = 10;
stringArray[0] = "this is string one";
stringArray[1] = "this is string two";
stringArray[2] = "this is string three";

registryToolsWriteValue(".", "HKCU", "test\\myKey", "string", "REG_SZ", "this is a sample string!"); // string
registryToolsWriteValue(".", "HKCU", "test\\myKey", "binary", "REG_BINARY", binaryArray); // binary array
registryToolsWriteValue(".", "HKCU", "test\\myKey", "dword", "REG_DWORD", 0xF8); // dword
registryToolsWriteValue(".", "HKCU", "test\\myKey", "expstr", "REG_EXPAND_SZ", "%PATH"); // expanding string
registryToolsWriteValue(".", "HKCU", "test\\myKey", "multistring", "REG_MULTI_SZ", stringArray); // many strings

// registryToolsEnumValues()
// let's enumerate the values under "HKEY_CURRENT_USER\test\myKey"
// on the local machine.

var myValues = registryToolsEnumValues(".", "HKCU", "test\\myKey")

// now let's print the values & types arrays (you probably want to run this script using cscript.exe
// so that you don't get tons of alert popups. Also be sure you read a
// real registry key if you run this program ;)
var j = 0;
while( j < myValues.values.length ) {
	WScript.Echo("Value " + myValues.values[j] + " is of type " + myValues.types[j]);
	j++;
	}
// simple as pie!

// now lets use the readValues function.. we're going to use
// the results of the enumValues call to do this, but you can
// pass hard coded stuff if you wish.
var myValName = myValues.values[0];
var myValType = myValues.types[0]; // these are for clarification

var myValue = registryToolsReadValue(".", "HKCU", "test\\myKey", myValName, myValType);
// now let's print the value!
// this will probably thow an error if we are trying to read a REG_MULTI_SZ
// but hey, its just a sample!
WScript.Echo("Value " + myValName + ", of type " + myValType + " contains '" + myValue + "'");

// registryToolsEnumKeys()
var myKeys = registryToolsEnumKeys(".", "HKCU", "test\\myKey");
j = 0;
WScript.Echo("keys:")
while( j < myKeys.length ){
	WScript.Echo(myKeys[j]);
	j++;
	}

// registryToolsDeleteValue()
registryToolsDeleteValue(".", "HKCU", "test\\myKey", "string");
registryToolsDeleteValue(".", "HKCU", "test\\myKey", "binary");
registryToolsDeleteValue(".", "HKCU", "test\\myKey", "dword");
registryToolsDeleteValue(".", "HKCU", "test\\myKey", "expstr");
registryToolsDeleteValue(".", "HKCU", "test\\myKey", "multistring");

// registryToolsDeleteKey()
registryToolsDeleteKey(".", "HKCU", "test\\myKey\\subKeyOne\\anotherChild");
registryToolsDeleteKey(".", "HKCU", "test\\myKey\\subKeyOne");
registryToolsDeleteKey(".", "HKCU", "test\\myKey\\subKeyTwo");
registryToolsDeleteKey(".", "HKCU", "test\\myKey");

