// These functions allow you to access the registry in // a safe way + for every user an other path will be used. // // Both variable and path should not begin with a slash (/). // // ExistsRegistry ( // [optional string] sub directory in the script's registry key, // [optional string] variable in the script's registry key // ) // Returns true if exists, false if not exists // // DeleteRegistry ( // [optional string] sub directory in the script's registry key, // [optional string] variable to remove, if not set, the whole directory will be removed // ) // Deletes a variable or key. // // ReadRegistry ( // [optional string] sub directory in the script's registry key, // [optional string] variable to read from, // [optional string] default value in case the variable is not set yet // ) // Reads the value of a key or variable, returns the value if found, returns default value if set, returns null if failed. // // WriteRegistry ( // [optional string] sub directory in the script's registry key, // [optional string] variable to read from, // [string] value to write, // [boolean] whether or not to overwrite if set already // ) // Writes a value to a key or variable, returns the written value if overwrite is true or value did not exist, returns original value if overwrite is false and value did exist, returns null if failed. function ExistsRegistry(path, variable) { if (path != null) { var RegPath = MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + path + "\\" + variable; } else { var RegPath = MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + variable; } var Shell = new ActiveXObject("WScript.Shell"); try { Shell.RegRead(RegPath); return true; } catch(error) { return false; } } function DeleteRegistry(path, variable) { if (path != null) { var RegPath = MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + path + "\\" + variable; } else { var RegPath = MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + variable; } var Shell = new ActiveXObject("WScript.Shell"); return Shell.RegDelete(RegPath); } function ReadRegistry(path, variable, value) { if (path != null) { var RegPath = MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + path + "\\" + variable; } else { var RegPath = MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + variable; } var Shell = new ActiveXObject("WScript.Shell"); try { return Shell.RegRead(RegPath); } catch(error) { if (value != null) { Shell.RegWrite(RegPath, value); return value; } else { return null; } } } function WriteRegistry(path, variable, value, overwrite) { if (path != null) { var RegPath = MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + path + "\\" + variable; } else { var RegPath = MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + variable; } var Shell = new ActiveXObject("WScript.Shell"); if (overwrite != false) { Shell.RegWrite(RegPath, value); return value; } else { try { return Shell.RegRead(RegPath); } catch(error) { Shell.RegWrite(RegPath, value); return value; } } }