RegistryConstants =
{
	HKEY_CLASSES_ROOT: 0x80000000,
    HKEY_CURRENT_USER: 0x80000001,
    HKEY_LOCAL_MACHINE: 0x80000002,
    HKEY_USERS: 0x80000003,
    HKEY_CURRENT_CONFIG: 0x80000005,
    HKEY_DYN_DATA: 0x80000006,
    REGISTRY_PATH: "SOFTWARE\\Microsoft\\MessengerGadget"
}


/************************************************************
          REGISTRY OBJECT - CONSTRUCTOR
 ************************************************************/
RegistryObj = function()
{
    var objSWbemLocator = new ActiveXObject("WbemScripting.SWbemLocator");
    var objSWbemServices = objSWbemLocator.ConnectServer(".", "root\\default");
    this.objRegistry = objSWbemServices.Get("StdRegProv");
	this.hive = RegistryConstants.HKEY_CURRENT_USER;
	this.path = RegistryConstants.REGISTRY_PATH;
}

RegistryObj.prototype =
{
    readDWORDValue:function(valueName) 
    {
        var method = this.objRegistry.Methods_.Item("GetDWORDValue");

        var params = method.InParameters.SpawnInstance_();
        params.hDefKey = this.hive;
        params.sSubKeyName = this.path;
        params.sValueName = valueName;

        var result = this.objRegistry.ExecMethod_(method.Name, params);
        return result.uValue;
    },

    readStringValue:function(valueName) 
    {
        var method = this.objRegistry.Methods_.Item("GetStringValue");

        var params = method.InParameters.SpawnInstance_();
        params.hDefKey = this.hive;
        params.sSubKeyName = this.path;
        params.sValueName = valueName;

        var result = this.objRegistry.ExecMethod_(method.Name, params);
        return result.sValue;
    },

    writeDWORDValue:function(valueName, value)
    {
        var method = this.objRegistry.Methods_.Item("SetDWORDValue");

        var params = method.InParameters.SpawnInstance_();
        params.hDefKey = this.hive;
        params.sSubKeyName = this.path;
        params.sValueName = valueName;
        params.uValue = value;

        var result = this.objRegistry.ExecMethod_(method.Name, params);
        return result.ReturnValue;
    },

    writeStringValue:function(valueName, value)
    {
        var method = this.objRegistry.Methods_.Item("SetStringValue");

        var params = method.InParameters.SpawnInstance_();
        params.hDefKey = this.hive;
        params.sSubKeyName = this.path;
        params.sValueName = valueName;
        params.sValue = value;

        var result = this.objRegistry.ExecMethod_(method.Name, params);
        return result.ReturnValue;
    },

    createKey:function()
    {
        var method = this.objRegistry.Methods_.Item("CreateKey");

        var params = method.InParameters.SpawnInstance_();
        params.hDefKey = this.hive;
        params.sSubKeyName = this.path;

        var result = this.objRegistry.ExecMethod_(method.Name, params);
        return result.ReturnValue;
    }
}