Registry Class - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Registry Class (/showthread.php?tid=76521)
Registry Class by LifelesS on 08-03-2007 at 07:01 PM
Well, I can just say this came out of the dance of my fingers
Ok, I'll say a little more...
It's a class I built so that you easily create, read and delete registry keys.
-------------------------------------------------------------------------------------------
How to use:
First you need to globally declare: 'var Regs = new Regs(SaveLocation)' -> where SaveLocation is a boolean, if it's 0,
it will save to MsgPlus.ScriptRegPath + Messenger.UserId, if it's 1 it will save to MsgPlus.ScriptRegPath + Messenger.MyEmail.
Then you can use Regs.methods():
Regs.Del(key) - deletes the 'key' registry;
Regs.Read(key) - reads the 'key' registry;
Regs.WriteStr(key, value, overwrite) - writes a string with 'key' name, 'value' value, overwrite is a bool, if omitted, overwrites;
Regs.WriteBool(key, value, overwrite) - writes a bool with 'key' name, 'value' - 0/1, overwrite is a bool, if omitted, overwrites;
-------------------------------------------------------------------------------------------
The file is on the attachment
RE: Registry Class by Ezra on 08-03-2007 at 07:17 PM
Your script looks ok, but it uses the wshell method that can be restrictive sometimes.
Matty made a script that uses the Registry API´s of windows directly
Attached is Matty´s Registry script that is included in Screenshot Sender 4
I´m not sure if there´s a newer version, you should contact Matty about that.
RE: Registry Class by LifelesS on 08-03-2007 at 07:19 PM
there's some problem with your attachment, but I have Matty's script, I'll give it a look
RE: Registry Class by Ezra on 08-03-2007 at 07:21 PM
There´s nothing wrong with my attachment?
RE: Registry Class by LifelesS on 08-03-2007 at 07:23 PM
btw, what do u mean by restrictive?
quote: There´s nothing wrong with my attachment?
I just see a lot of this
quote: �/�/� �R�e�g�i�s�t�r�y� �v�a�l�u�e� �t�y�p�e�s�
�
� �v�a�r� �R�E�G�_�N�O�N�E� �=� �0�;� � � � � � � � �/�*� �'�N�o� �v�a�l�u�e� �t�y�p�e�'� � � � � � � � � �*�/�
�
� �v�a�r� �R�E�G�_�S�Z� �=� �1�;� � � � � � � � � �/�*� �'�U�n�i�c�o�d�e� �n�u�l� �t�e�r�m�i�n�a�t�e�d� �s�t�r�i�n�g�'� � � � � � �*�/�
�
RE: Registry Class by Ezra on 08-03-2007 at 07:28 PM
quote: Originally posted by LifelesS
btw, what do u mean by restrictive?
IIRC there was a limit of some kind, can't remember exactly.
And Matty's script allows Enumeration of keys.
quote: Originally posted by LifelesS
I just see a lot of this
That's probably because your browser can't figure out that the file encoding is UCS2-LE (UTF16-LE)
EDIT: Searching the forums I found at least one thing:
quote: Originally posted by J-Thread
Tip
RegWrite will write at most one DWORD to a REG_BINARY value. Larger values are not supported with this method.
EDIT2: Found some more:
quote: Originally posted by CookieRevised
RegWrite, RegRead and RegDelete are the only ones that JScript knows and those methods are very, and I mean very, limited.
eg:
* You can not check if a registry key exists or not with RegRead; it will produce an error. => can be worked around using error checking.
* You can not write bigger values than a DWORD to a binary registry value (this means no binary data strings for example)
* You can not write a REG_MULTI_SZ value with RegWrite
* You can not enumerate registry keys
* and the list goes on...
RE: RE: Registry Class by LifelesS on 08-03-2007 at 07:34 PM
quote: Originally posted by Ezra
quote: Originally posted by LifelesS
btw, what do u mean by restrictive?
IIRC there was a limit of some kind, can't remember exactly.
Humm... kk
quote: Originally posted by Ezra
quote: Originally posted by LifelesS
I just see a lot of this
That's probably because your browser can't figure out that the file encoding is UCS2-LE (UTF16-LE)
Using Firefox...
I'm looking at the file now, still going to take some time to undersand it all, it starts going a little out of my knowledge
RE: Registry Class by matty on 08-03-2007 at 08:16 PM
quote: Originally posted by LifelesS
I just see a lot of this
Because you saved the file as Unicode that is why the board isn't showing it properly. It assumes that the charset for a text file is ANSI not UNICODE.
However not to rain on anyones parade but I did make an updated version of the Registry editor. The previous one was a joke this one uses DRY (Don't Repeat Yourself - Eljay )
Attached is the newer version.
The functions included are:
- Registry_CreateKey
- Registry_DeleteKey
- Registry_DeleteKeyValue
- Registry_KeyExist
- Registry_KeyValueExist
- Registry_EnumSubkeys
- Registry_EnumKeys
- Registry_GetKeyValue
- Registry_SetKeyValue
- Registry_CloseKey
RE: RE: Registry Class by LifelesS on 08-03-2007 at 08:19 PM
quote: Originally posted by matty
However not to rain on anyones parade but I did make an updated version of the Registry editor. The previous one was a joke this one uses DRY (Don't Repeat Yourself - Eljay )
The more the better
RE: Registry Class by matty on 08-03-2007 at 08:23 PM
I forgot to mention over the weekend or sometime next week I will be extending the functionality and including RegDeleteTree and RegCopyTree, now because these are native to Windows Vista I will have to code the Windows XP side myself but that wont be a problem. What is the use you ask? None really Just it would be nice to have a full Registry Class (although mine isn't a class it is still good haha.)
RE: Registry Class by LifelesS on 08-03-2007 at 08:53 PM
I can try to turn it into a class if you like
I think it would be VERY NICE to have a class like that. It would save the scripters a lot of work.
That and a class for using ini files for settings too, I was thinking of building it when I finished regsclass
RE: Registry Class by Ezra on 08-03-2007 at 10:41 PM
quote: Originally posted by LifelesS
I can try to turn it into a class if you like
Does it really need to be a class?
Sometimes classes can be very handy, but sometimes also over-complicate matters.
quote: Originally posted by matty
I forgot to mention over the weekend or sometime next week I will be extending the functionality
That's great, maybe you could publicly release your class somewhere so that other scripters can easily find and use it.
Same goes for some other very good classes/functions made by other people, eg -dt-'s classes
RE: RE: Registry Class by LifelesS on 08-03-2007 at 10:47 PM
quote: Originally posted by Ezra
quote: Originally posted by LifelesS
I can try to turn it into a class if you like
Does it really need to be a class?
Sometimes classes can be very handy, but sometimes also over-complicate matters.
It all depends on how the code is written..
RE: Registry Class by matty on 08-04-2007 at 12:19 AM
LifelesS, honestly if I wanted it to be made a class I would have made it one, however something like this doesn't need multiple instances therefore is not needed.
RE: RE: Registry Class by LifelesS on 08-04-2007 at 12:36 AM
quote: Originally posted by matty
LifelesS, honestly if I wanted it to be made a class I would have made it one, however something like this doesn't need multiple instances therefore is not needed.
Yeah I agree, totally
RE: Registry Class by matty on 08-04-2007 at 12:42 AM
I got a PM asking how to use the Registry Enum components well this is how it is done.
code: function OnEvent_Initialize(MessengerStart) {
var objSubKeys = {}
Registry_EnumSubkeys(HKCU, 'Software\\Patchou\\Messenger Plus! Live', objSubKeys);
for (var objSubKey in objSubKeys) {
Debug.Trace(objSubKey);
var objValues = {};
Registry_EnumKeys(HKCU, 'Software\\Patchou\\Messenger Plus! Live\\'+objSubKey+'\\Preferences', objValues);
for (var objValue in objValues) {
Debug.Trace(' > '+objValue+' : '+objValues[objValue]);
}
}
}
Another function you can do in the script is to print out a registry tree.
code: function OnEvent_Initialize(MessengerStart) {
Debug.Trace('Software\\Patchou\\Messenger Plus! Live');
GetRegistryTree(HKCU, 'Software\\Patchou\\Messenger Plus! Live', ' ');
}
function GetRegistryTree(Location, Key, prefix) {
var objSubKeys = {};
var objValues = {};
Registry_EnumKeys(Location, Key, objValues);
for (var objValue in objValues) {
Debug.Trace(prefix+'> '+objValue+'\t: '+objValues[objValue]);
}
Registry_EnumSubkeys(Location, Key, objSubKeys);
for (var objSubKey in objSubKeys) {
Debug.Trace(prefix+Key+'\\'+objSubKey);
GetRegistryTree(Location, Key+'\\'+objSubKey, prefix+' ');
}
}
And a Delete Tree function
code: function OnEvent_Initialize(MessengerStart) {
Registry_DeleteTree(HKEY_LOCAL_MACHinE, 'Software\\Patchou');
Debug.Trace('Registry_DeleteKey[\'Software\\Patchou]\' : '+Registry_DeleteKey(HKEY_LOCAL_MACHINE, 'Software\\Patchou'));
}
function Registry_DeleteTree(Location, Key) {
var objSubKeys = {};
var objValues = {};
Registry_EnumKeys(Location, Key, objValues);
for (var objValue in objValues) {
Debug.Trace('Registry_DeleteKeyValue['+Key+'\\'+objValue+'] : '+Registry_DeleteKeyValue(Location, Key, objValue));
}
Registry_EnumSubkeys(Location, Key, objSubKeys);
for (var objSubKey in objSubKeys) {
Registry_DeleteTree(Location, Key+'\\'+objSubKey);
Debug.Trace('Registry_DeleteKey['+Key+'\\'+objSubKey+'] : '+Registry_DeleteKey(Location, Key+'\\'+objSubKey));
}
}
RE: Registry Class by Matti on 08-04-2007 at 11:27 AM
I've downloaded your latest registry library, but there seems to be a bug in the Registry_KeyValueExist function.
The function code says:
code: function Registry_KeyValueExist(lKeyLocation, sKey, sKeyName){
var hKey = Interop.Allocate(4);
var sTmp = Interop.Allocate(4);
var lActualType = Interop.Allocate(4);
var lRetVal = Interop.Call('advapi32.dll', 'RegOpenKeyExW', lKeyLocation, sKey, 0, KEY_READ, hKey);
if (lRetVal === ERROR_SUCCESS){
lRetVal = Interop.Call('advapi32.dll', 'RegQueryValueExW', hKey.ReadDWORD(0), sKeyName, 0, lActualType, sTmp, 0);
Registry_CloseKey(hKey.ReadDWORD(0));
return lRetVal === ERROR_SUCCESS;
}else{ return false; }
}
However, the function always returned false. This caused my script to restore the defaults every time the script started up, and so I simply had to get this fixed. When I debugged this, I found that after the RegQueryValueExW call, lRetVal was equal to 87. After looking up this value, I found that this was the ERROR_INVALID_PARAMETER constant. So, I checked the parameters section of this function's MSDN page and found this:
quote: Originally posted by MSDN: RegQueryValueEx
lpcbData
[in, out] A pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes. When the function returns, this variable contains the size of the data copied to lpData.
The lpcbData parameter can be NULL only if lpData is NULL.
...
Now, in the function call lpcbData is 0 but lpData isn't! So, after modifying the call to:
code: lRetVal = Interop.Call('advapi32.dll', 'RegQueryValueExW', hKey.ReadDWORD(0), sKeyName, 0, 0, 0, 0);
it worked!
This means, that you can replace the whole function by just this:
code: function Registry_KeyValueExist(lKeyLocation, sKey, sKeyName){
var hKey = Interop.Allocate(4);
var lRetVal = Interop.Call('advapi32.dll', 'RegOpenKeyExW', lKeyLocation, sKey, 0, KEY_READ, hKey);
if (lRetVal === ERROR_SUCCESS){
lRetVal = Interop.Call('advapi32.dll', 'RegQueryValueExW', hKey.ReadDWORD(0), sKeyName, 0, 0, 0, 0);
Registry_CloseKey(hKey.ReadDWORD(0));
return lRetVal === ERROR_SUCCESS;
}else{ return false; }
}
This leaves with just one (!) instead of three buffers used.
RE: Registry Class by matty on 08-04-2007 at 12:02 PM
Thanks I will fix that, I never used that function or tested it I just assumed it worked my bad. Sorry all.
RE: Registry Class by -dt- on 08-04-2007 at 12:16 PM
hm I created a registry class a while ago
http://websvn.thedt.net/Scripts/markup/213/codedump___registryClass.js
RE: Registry Class by ShawnZ on 08-04-2007 at 12:18 PM
javascript doesn't have classes. if you want to make it an object, you wouldn't be using multiple instances anyway. you'd just be replacing _ with ..
|