Shoutbox

Registry Editing in scripts. - 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 Editing in scripts. (/showthread.php?tid=61525)

Registry Editing in scripts. by Terry_K on 06-26-2006 at 08:31 AM

Would anyone know how to edit the registry using a Messenger Plus! Live script? I can do it with Visual Basic .NET but it would help if someone told me how to write it in a script.

Thanks in advance.


RE: Registry Editing in scripts. by Ezra on 06-26-2006 at 08:34 AM

quote:
Originally posted by Scripting Manual

//Write the value
var Shell = new ActiveXObject("WScript.Shell");
var ValRegPath = MsgPlus.ScriptRegPath + "EnableOpt";
Shell.RegWrite(ValRegPath, 1);

//Read the value
var EnableOpt = Shell.RegRead(ValRegPath);
Debug.Trace("EnableOpt current value: " + EnableOpt);


I would read that Manual If I were you, lots of examples in it.
RE: Registry Editing in scripts. by Terry_K on 06-26-2006 at 08:36 AM

Thank you.

If by manual you mean scripting documentation, i'll do that.


RE: RE: Registry Editing in scripts. by mathieumg on 06-26-2006 at 11:48 AM

quote:
Originally posted by Terry_K
If by manual you mean scripting documentation


That's what he meant ;)
RE: Registry Editing in scripts. by The_Joker on 06-27-2006 at 01:00 PM

Tried to use this script but with a function to read & write.
Write works great, but reads gives an error.
If I try the Debug.Trace it works, but return doesn't.
(PS. Taken the script from another post, copied and it doesn't work).

code:
function ReadRegistry(key)
{
var Shell = new ActiveXObject("WScript.Shell");
return value = Shell.RegRead(MsgPlus.ScriptRegPath + key);
}

RE: Registry Editing in scripts. by CookieRevised on 06-27-2006 at 01:48 PM

quote:
Originally posted by The_Joker
Tried to use this script but with a function to read & write.
Write works great, but reads gives an error.
If I try the Debug.Trace it works, but return doesn't.
(PS. Taken the script from another post, copied and it doesn't work).

code:
function ReadRegistry(key)
{
var Shell = new ActiveXObject("WScript.Shell");
return value = Shell.RegRead(MsgPlus.ScriptRegPath + key);
}

To analyze where the error is in such situations you should lookup what each object exactly will return in its documentation....

If you do that and you look up MsgPlus.ScriptRegPath in the scripting documentation (or you do simply a test with that object alone) you'll see that it returns a registry path.

Now you append the variable "key" to it, in other words you append a string to a path without anything else.... thus there is something missing in between... Think of it as a file and directory:

"C:\Program Files\MSN Messenger" would be the path and "msnmsgr.exe" the file, append the two and you'll get:
"C:\Program Files\MSN Messengermsnmsgr.exe" which is obviously something not correct as there is a "\" missing...


In other words:
    Shell.RegRead(MsgPlus.ScriptRegPath + "\\" + key);
note that you need to put a double "\" as it is otherwise interpreted as a literal escape code

So change that in your example and run it again....


The script will again not give the desired result. Why? Because you have other errors. The proper syntax for a "return" statement is:
    return <variable>;

and "value = Shell.RegRead(MsgPlus.ScriptRegPath + key)" is not a value but a statement on its own. So either you do:

    var value = Shell.RegRead(MsgPlus.ScriptRegPath + key);
    return value;

or simply:

    return Shell.RegRead(MsgPlus.ScriptRegPath + key);
RE: Registry Editing in scripts. by The Brain on 06-27-2006 at 01:57 PM

quote:
From the Scripting Documentation
A string containing the path to the script's registry key. The path begins with "HKCU\" to designate the HKEY_CURRENT_USER key and ends with a backslash.

Sorry Cookie, but Plus gives you a Registry path ending with a backslash. If fixing the return statement doesn't fix it, I would imagine the error is because the variable key is not valid. Registry keys are case sensitive as awell, aren't they? Open regedit (via Start > Run) and check that the key you are looking for is actually there.

The Scripts Registry path is:
"HKEY_CURRENT_USER\Software\Patchou\Messenger Plus! Live\GlobalSettings\Scripts\"
Followed by the name of the script.
RE: Registry Editing in scripts. by CookieRevised on 06-27-2006 at 02:08 PM

quote:
Originally posted by The Brain
Sorry Cookie, but Plus gives you a Registry path ending with a backslash.
yeah, I noticed and was editing my post while you posted... Thanks for notifying though (y)

quote:
Originally posted by The Brain
Registry keys are case sensitive as awell, aren't they?
Nope, they are case insensitive...

PS: note that the ActiveX registry object methods are rather limited though... to do more registry manipulation (or even writing binary data etc) you need to use the Windows APIs.
RE: Registry Editing in scripts. by The_Joker on 06-27-2006 at 02:32 PM

yeah, thought about the "return value = ..." thing...
I tried to play with it for over a hour and didn't succeed.
It works perfectly with Debug.Trace, so the problem is that it refuses to return the value.
Do I need to set the type of the return value or something?

BTW, tried to put it in value and "return value", tried just "return  Shell.Reg...", nothing works.

hmm, didn't tried to put it as a code in the orginal function and not in a separate function, but I use it too many times so it will be annoying and won't look nice...

[offtopic]
Can't check it now, back to good old 7.5 :P
Is it just me or WML doesn't seems so user-friendly (visually) like MSNM?
[/offtopic]


RE: Registry Editing in scripts. by matty on 06-27-2006 at 02:49 PM

This is what I use for Screenshot Sender 4. If  you choose to keep the script you must keep the header regardless if you change the file or not.

This script is going to be apart of the snippets that will be available on http://mpscripts.net

For now its hosted on my server.

http://mattyg.ca/geshi/registry.php

Geshi : Generic Syntax Highlighter
http://qbnz.com/highlighter/


Note : If there are any errors with it please PM me. As well I am going to be changing the functions around a bit so I will update the file on my server and the latest one will be on http://mpscripts.net when we get enough snippets made.


RE: Registry Editing in scripts. by The_Joker on 06-27-2006 at 03:19 PM

This script is completely different from the one mentioned here.
Dunno if ur script work, as I said before I can't check it now.
I prefer something simple and easy...
Ne1 know how to fix the ReadRegistry function?


RE: Registry Editing in scripts. by matty on 06-27-2006 at 03:25 PM

quote:
Originally posted by The_Joker
This script is completely different from the one mentioned here.
Dunno if ur script work, as I said before I can't check it now.
I prefer something simple and easy...
Ne1 know how to fix the ReadRegistry function?
How is my script different? You are trying to use an ActiveXObject to read the registry. I am using the Windows API to read the registry. I don't see how this is different at all in any way, aside from mione providing more control; longer code; and using more memory.

code:
var sReturnValue = GetStringValue(HKEY_CURRENT_USER, 'Software\\Patchou\\Messenger Plus! Live', 'DefaultUser');
Debug.Trace('sReturnValue: '+sReturnValue);

Again I don't see how they differ at all.
RE: RE: Registry Editing in scripts. by CookieRevised on 06-28-2006 at 01:15 AM

quote:
Originally posted by The_Joker
Ne1 know how to fix the ReadRegistry function?
already answered

CookieRevised's reply to Registry Editing in scripts.

quote:
Originally posted by CookieRevised
The proper syntax for a "return" statement is:
    return <variable>;

and "value = Shell.RegRead(MsgPlus.ScriptRegPath + key)" is not a value but a statement on its own. So either you do:

    var value = Shell.RegRead(MsgPlus.ScriptRegPath + key);
    return value;

or simply:

    return Shell.RegRead(MsgPlus.ScriptRegPath + key);


RE: RE: RE: Registry Editing in scripts. by The_Joker on 06-28-2006 at 10:20 AM

quote:
Originally posted by CookieRevised
The proper syntax for a "return" statement is:
    return <variable>;

and "value = Shell.RegRead(MsgPlus.ScriptRegPath + key)" is not a value but a statement on its own. So either you do:

    var value = Shell.RegRead(MsgPlus.ScriptRegPath + key);
    return value;

or simply:

    return Shell.RegRead(MsgPlus.ScriptRegPath + key);


As I said, it doesn't work either...
The return thing gives an error not matter what I do.
RE: Registry Editing in scripts. by Ezra on 06-28-2006 at 10:26 AM

What is the error code that you get?

And what code do you use exactly?


RE: RE: Registry Editing in scripts. by The_Joker on 06-28-2006 at 10:31 AM

quote:
Originally posted by Ezra
What is the error code that you get?

And what code do you use exactly?

1. Back to good old 7.5, so I can't check the error number.

2. The code is/are:
code:
function ReadRegistry(key)
{
    var Shell = new ActiveXObject("WScript.Shell");
    return Shell.RegRead(MsgPlus.ScriptRegPath + key);
}
code:
function ReadRegistry(key)
{
    var Shell = new ActiveXObject("WScript.Shell");
    var value = Shell.RegRead(MsgPlus.ScriptRegPath + key);
    return value;
}
Both gives the same error if I remember correctly.
RE: Registry Editing in scripts. by Ezra on 06-28-2006 at 10:38 AM

Only thing I can think of is that the key doesn't excist...


RE: RE: Registry Editing in scripts. by The_Joker on 06-28-2006 at 10:41 AM

quote:
Originally posted by Ezra
Only thing I can think of is that the key doesn't excist...


I checked it exists.
It works okay with Debug.Trace but return doesn't.
Also I checked with regedit, it's there.
RE: Registry Editing in scripts. by matty on 06-28-2006 at 12:18 PM

Have you tried the script I posted? Just save it to a seperate JS file then call its function.

I posted it for a reason I know it works cause I actually use it.


RE: RE: RE: Registry Editing in scripts. by CookieRevised on 06-29-2006 at 06:12 PM

quote:
Originally posted by The_Joker
quote:
Originally posted by Ezra
Only thing I can think of is that the key doesn't excist...

I checked it exists.
It works okay with Debug.Trace but return doesn't.
Also I checked with regedit, it's there.
There is nothing wrong in that latest code. The error is as Ezra suggested the key value you give to the function which doesn't exit or whatever. It works fine here.