What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » my first script any help would be appriciated..

Pages: (2): « First [ 1 ] 2 » Last »
my first script any help would be appriciated..
Author: Message:
Yustme
Junior Member
**


Posts: 85
40 / – / –
Joined: Aug 2005
O.P. my first script any help would be appriciated..
Hi,

Im trying to create a script which logs me in automatically in several accounts. I know there is one out there, but its bugged. Tried fixing it, but it's too messed up to understand it.

The error i get is that the script is defective and that it can't be started.

Here is my code:

JScript code:
 
if(Messenger.Version >= 8.5)
{
    var WLMkey = 'SOFTWARE\\Microsoft\\MSNMessenger';
    var WLMexe = 'SOFTWARE\\Microsoft\\Windows Live\\Messenger';
}
 
else
{
    var WLMkey = 'SOFTWARE\\Microsoft\\MSNMessenger';
    var WLMexe = WLMkey;
}
var MPLkey = 'SOFTWARE\\Patchou\\Messenger Plus! Live';
//var MPLscriptkey = (MsgPlus.ScriptRegPath).replace(/HKCU\\/i, '');
 
var delayOpenWnd = 2000;
 
function OnEvent_Initialize(MessengerStart)
{
    if ( Messenger.MyStatus < STATUS_INVISIBLE ) return;
    MsgPlus.AddTimer('windowDelayer', delayOpenWnd);
 
}
 
function OnEvent_Uninitialize(MessengerExit)
{
    MsgPlus.CancelTimer('windowDelayer');
}
 
function SetDefaultAccount()
{
    var emailList = new Array();
    emailList.push('mailaddress@hotmail.com');
    emailList.push('mailaddress@hotmail.com');
    emailList.push('mailaddress@hotmail.com');
 
   
    for(int i = 0; i < emailList.length; i++)
    {
        var email = emailList[i];
        SetBinaryValue(HKEY_CURRENT_USER, WLMkey + '\\PerPassportSettings', 'DefaultMemberName', email);
        SetStringValue(HKEY_CURRENT_USER, MPLkey, 'DefaultUser', email);
        ExecuteWLM();
    }
    //Debug.Trace('Set default account: ' + email);
}
 
function ExecuteWLM()
{
    new ActiveXObject("Shell.Application").ShellExecute("C:/Program Files (x86)/Windows Live/Messenger/" + "msnmsgr.exe", "", "", "open", 1);
}
 
function OnEvent_Timer(timerId)
{
    switch(timerId)
    {
        case 'windowDelayer':
            SetDefaultAccount();
        break;
        default:
       
    }
}



Can't seem to get the code highlighted..

This post was edited on 02-13-2010 at 04:58 PM by Yustme.
02-13-2010 03:25 PM
Profile PM Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
29 / Male / Flag
Joined: Nov 2006
Status: Away
RE: my first script any help would be appriciated..
quote:
Originally posted by Yustme
JScript code:
for(int i = 0; i < emailList.length; i++)



instead of "int i", use "var i" and it will work.

quote:
Can't seem to get the code highlighted..
[code=JScript]blah[/code]

This post was edited on 02-13-2010 at 04:44 PM by roflmao456.
[quote]
Ultimatess6
: What a noob mod
02-13-2010 04:43 PM
Profile PM Web Find Quote Report
Yustme
Junior Member
**


Posts: 85
40 / – / –
Joined: Aug 2005
O.P. RE: RE: my first script any help would be appriciated..
quote:
Originally posted by roflmao456
quote:
Originally posted by Yustme
JScript code:
for(int i = 0; i < emailList.length; i++)



instead of "int i", use "var i" and it will work.

quote:
Can't seem to get the code highlighted..
[code=JScript]blah[/code]


Hi,

Thank you twice!

I got another small question. I put a delay for the windows, but somehow that doesn't work. The msn windows open too soon after each other. How can I delay this in a proper way?


Edit:
It seems to skip all the email addresses to log in and logs only the last email address. Something wrong with my timer?

This post was edited on 02-13-2010 at 05:30 PM by Yustme.
02-13-2010 04:58 PM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: my first script any help would be appriciated..
quote:
Originally posted by Yustme
It seems to skip all the email addresses to log in and logs only the last email address. Something wrong with my timer?
Well yes, you should be putting a delay inside your loop instead of before calling the function with the loop.
  • Make global variables from the e-mail address array and the current loop position.
  • Write a function to use as timer callback:
    1. Read the current item using the global variables.
    2. Set the registry keys and launch Messenger.
    3. Check for remaining items in the list. If there are none, exit.
    4. Increment the position and create a new delay timer for the next iteration.
I could give you the code to do that myself, but I believe it'd be a good exercise to try this yourself first. If you find yourself having trouble with getting the code right, reply here and we'll see how we can help you. :)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
02-13-2010 07:02 PM
Profile E-Mail PM Web Find Quote Report
Yustme
Junior Member
**


Posts: 85
40 / – / –
Joined: Aug 2005
O.P. RE: RE: my first script any help would be appriciated..
quote:
Originally posted by Matti
quote:
Originally posted by Yustme
It seems to skip all the email addresses to log in and logs only the last email address. Something wrong with my timer?
Well yes, you should be putting a delay inside your loop instead of before calling the function with the loop.
  • Make global variables from the e-mail address array and the current loop position.
  • Write a function to use as timer callback:
    1. Read the current item using the global variables.
    2. Set the registry keys and launch Messenger.
    3. Check for remaining items in the list. If there are none, exit.
    4. Increment the position and create a new delay timer for the next iteration.
I could give you the code to do that myself, but I believe it'd be a good exercise to try this yourself first. If you find yourself having trouble with getting the code right, reply here and we'll see how we can help you. :)



Hi Matti,

Thank you! I'll be back in a few hours to tell my progress.
02-13-2010 07:18 PM
Profile PM Find Quote Report
Yustme
Junior Member
**


Posts: 85
40 / – / –
Joined: Aug 2005
O.P. RE: my first script any help would be appriciated..
Hi Matti,

I got it almost completely working with your guidance. I still got a minor problem.

Here is my code:

JScript code:
var emailList = new Array();
var counter = 0;
var delayOpenWnd = 2000;
 
 
var MPLkey = 'SOFTWARE\\Patchou\\Messenger Plus! Live';
var WLMkey;
var WLMexe;
 
if(Messenger.Version >= 8.5)
{
    WLMkey = 'SOFTWARE\\Microsoft\\MSNMessenger';
    WLMexe = 'SOFTWARE\\Microsoft\\Windows Live\\Messenger';
}
 
else
{
    WLMkey = 'SOFTWARE\\Microsoft\\MSNMessenger';
    WLMexe = WLMkey;
}
 
 
function OnEvent_Initialize(MessengerStart)
{
    if ( Messenger.MyStatus < STATUS_INVISIBLE ) return;
   
    emailList.push('test1@hotmail.com');
    emailList.push('test2@hotmail.com');
    emailList.push('test3@hotmail.com');
    emailList.push('test4@hotmail.com');
   
    MsgPlus.AddTimer('windowDelayer', delayOpenWnd);
}
 
function OnEvent_Uninitialize(MessengerExit)
{
    MsgPlus.CancelTimer('windowDelayer');
}
 
 
function ExecuteWLM()
{
    new ActiveXObject("Shell.Application").ShellExecute("C:/Program Files (x86)/Windows Live/Messenger/" + "msnmsgr.exe", "", "", "open", 1);
}
 
function OnEvent_Timer(timerId)
{
    switch(timerId)
    {
        case 'windowDelayer':
            var email = emailList[counter];
            counter++;
            SetBinaryValue(HKEY_CURRENT_USER, WLMkey + '\\PerPassportSettings', 'DefaultMemberName', email);
            SetStringValue(HKEY_CURRENT_USER, MPLkey, 'DefaultUser', email);
            ExecuteWLM();
            Debug.Trace("Set default account = " + email);
            MsgPlus.AddTimer('windowDelayer', delayOpenWnd);
        break;
        default:
    }
}
 
 
function OnEvent_SigninReady(emailaddr)
{
    var emailstat = Messenger.MyEmail;
    if(Messenger.MyStatus != STATUS_UNKNOWN)
    {
        Debug.Trace("User signed in, email = " = emailaddr + '\n');
        Debug.Trace("emailstat = " + emailstat + '\n');
    }
}



I got another quick question. Is there anything in this code that I don't need? for example the OnEvent_SigninReady?

Not sure what it should do.


Also, the function SetBinaryValue takes 4 arguments, but i'm only passing it 3.

JScript code:
function SetBinaryValue(lKeyLocation, sKey, sKeyName, sKeyValue)
{
Debug.Trace("sKeyValue = " + sKeyValue);
    var hKey = Interop.Allocate(4);
    var lBufferSize = Interop.Allocate(4);
        lBufferSize.WriteDWORD(0, 2 * sKeyValue.length + 2);
    var lRetVal = Interop.Call('advapi32.dll', 'RegOpenKeyExW', lKeyLocation, sKey, 0, KEY_WRITE, hKey);
        if(lRetVal == ERROR_SUCCESS)
        {
            lRetVal = Interop.Call('advapi32.dll', 'RegSetValueExW', hKey.ReadDWORD(0), sKeyName, 0, REG_BINARY, sKeyValue, lBufferSize.ReadDWORD(0));
            if(lRetVal == ERROR_SUCCESS)
            {
                CloseKey(hKey);
                return true;
            }
            else
            {
            return false;
            }
        }
        else
        {
        return false;
        }
}


Any idea what sKeyValue should be?

It gives me an error in the debug window. It says:

Error: 'length' is null or not an object (code: -2146823281)
       File: _Registry.js. Line: 145.



This would be the affected line:

lBufferSize.WriteDWORD(0, 2 * sKeyValue.length + 2);


In function:

SetBinaryValue()

This post was edited on 02-14-2010 at 12:03 AM by Yustme.
02-14-2010 12:02 AM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: my first script any help would be appriciated..
The reason why you're getting that error is because you're not checking how much e-mail addresses there are left in the array. You're simply incrementing the counter without checking whether it exceeds the length of the array.

By doing that, you end up with the email variable becoming undefined after a while. This won't throw an error immediately, so the script will continue and pass it as parameter to SetBinaryValue. However as soon as you try to access the length property of sKeyValue, an error will be thrown since there is no length property in undefined.

Looking at your code, it seems that you should have been able to find this out. You're tracing the value of sKeyValue at the start of SetBinaryValue so normally you should have found "sKeyValue = undefined" in your debugger.

Javascript code:
var emailList = [ 'test1@hotmail.com', 'test2@hotmail.com', 'test3@hotmail.com', 'test4@hotmail.com' ];
// ...
 
function OnEvent_Initialize(MessengerStart)
{
    // Check if there's anything to be done
    if(emailList.length > 0) {
        MsgPlus.AddTimer('windowDelayer', delayOpenWnd);
    }
}
 
// ...
 
function OnEvent_Timer(timerId)
{
    switch(timerId)
    {
        case 'windowDelayer':
            var email = emailList[counter];
            SetBinaryValue(HKEY_CURRENT_USER, WLMkey + '\\PerPassportSettings', 'DefaultMemberName', email);
            SetStringValue(HKEY_CURRENT_USER, MPLkey, 'DefaultUser', email);
            ExecuteWLM();
            Debug.Trace("Set default account = " + email);
 
            // Check if we should continue
            if(counter < emailList.length) {
                counter++;
                MsgPlus.AddTimer('windowDelayer', delayOpenWnd);
            }
        break;
    }
}

As you can see, despite of the debugger throwing an error inside SetBinaryValue, there was nothing wrong with that function. This is a good lesson for a developer - never rely solely on the error information! ;)

On another note, there seems to be a few more oddities in your script:
  • When the OnEvent_Initialize function is called on Messenger start-up, Messenger.MyStatus will still be 0 and thus your function will return immediately. This means that the emailList array will never be populated, causing your whole script to fail. I changed this in the code snippet above by populating the array as soon as its declared and by removing the status check at initialisation.
  • What happens when the other Messenger instances are opened? Is the script going to be executed for all those instances as well? Would that mean that all those script instances will keep opening new Messenger instances? Or am I wrong about this?
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
02-14-2010 11:04 AM
Profile E-Mail PM Web Find Quote Report
Yustme
Junior Member
**


Posts: 85
40 / – / –
Joined: Aug 2005
O.P. RE: RE: my first script any help would be appriciated..
quote:
Originally posted by Matti
The reason why you're getting that error is because you're not checking how much e-mail addresses there are left in the array. You're simply incrementing the counter without checking whether it exceeds the length of the array.

By doing that, you end up with the email variable becoming undefined after a while. This won't throw an error immediately, so the script will continue and pass it as parameter to SetBinaryValue. However as soon as you try to access the length property of sKeyValue, an error will be thrown since there is no length property in undefined.

Looking at your code, it seems that you should have been able to find this out. You're tracing the value of sKeyValue at the start of SetBinaryValue so normally you should have found "sKeyValue = undefined" in your debugger.

Javascript code:
var emailList = [ 'test1@hotmail.com', 'test2@hotmail.com', 'test3@hotmail.com', 'test4@hotmail.com' ];
// ...
 
function OnEvent_Initialize(MessengerStart)
{
    // Check if there's anything to be done
    if(emailList.length > 0) {
        MsgPlus.AddTimer('windowDelayer', delayOpenWnd);
    }
}
 
// ...
 
function OnEvent_Timer(timerId)
{
    switch(timerId)
    {
        case 'windowDelayer':
            var email = emailList[counter];
            SetBinaryValue(HKEY_CURRENT_USER, WLMkey + '\\PerPassportSettings', 'DefaultMemberName', email);
            SetStringValue(HKEY_CURRENT_USER, MPLkey, 'DefaultUser', email);
            ExecuteWLM();
            Debug.Trace("Set default account = " + email);
 
            // Check if we should continue
            if(counter < emailList.length) {
                counter++;
                MsgPlus.AddTimer('windowDelayer', delayOpenWnd);
            }
        break;
    }
}

As you can see, despite of the debugger throwing an error inside SetBinaryValue, there was nothing wrong with that function. This is a good lesson for a developer - never rely solely on the error information! ;)

On another note, there seems to be a few more oddities in your script:
  • When the OnEvent_Initialize function is called on Messenger start-up, Messenger.MyStatus will still be 0 and thus your function will return immediately. This means that the emailList array will never be populated, causing your whole script to fail. I changed this in the code snippet above by populating the array as soon as its declared and by removing the status check at initialisation.
  • What happens when the other Messenger instances are opened? Is the script going to be executed for all those instances as well? Would that mean that all those script instances will keep opening new Messenger instances? Or am I wrong about this?



Hi Matti,

I forgot about that check with length! :$

I did found that the "sKeyValue = undefined" in the debugger. But I thought that was because I didn't pass 4 argument to that function. I only passed 3 to it.

Well the script executes all the messenger windows and signs in all the email addresses. Then it stops. It doesn't repeat this step for all instances of messenger.

Good point though, because my 3th try making such a script opened like 8 instances of messenger over and over.

I got another quick question. Is there any way to check which email addresses have been logged in?

This post was edited on 02-14-2010 at 12:32 PM by Yustme.
02-14-2010 11:29 AM
Profile PM Find Quote Report
petsas
New Member
*


Posts: 4
Joined: Jul 2010
RE: my first script any help would be appriciated..
Did anyone find the answer to the last question?

Is there any way to check which email addresses have been logged in?

That's because we have to know which accounts are logged in, so as the procedure to stop
when all accounts are successfully created.

If there is no way to do that, then each of the accounts that will be created will run this script,
as a result this script will produce always new accounts..

any ideas??
07-02-2010 01:49 PM
Profile E-Mail PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
RE: my first script any help would be appriciated..
You could get the script to check for a registry key, and if it doesn't exist, it should create one because it is the first launch.

Javascript code:
// add to the top
var shell = new ActiveXObject("WScript.Shell");
 
// ...
 
function OnEvent_Initialize(MessengerStart)
{
    try {
        // value exists, already running, exit now
        shell.RegRead(MsgPlus.ScriptRegPath + "\\IsRunning");
        return false;
    } catch (error) {
        // not yet running, make a registry value, continue
        shell.RegWrite(MsgPlus.ScriptRegPath + "\\IsRunning", "1");
    }
 
    // Check if there's anything to be done
    if(emailList.length > 0) {
        MsgPlus.AddTimer('windowDelayer', delayOpenWnd);
    } else {
        // finished, delete the registry key
        shell.RegDelete(MsgPlus.ScriptRegPath + "\\IsRunning");
    }
}
 
// ...


This post was edited on 07-02-2010 at 02:09 PM by whiz.
07-02-2010 02:07 PM
Profile E-Mail PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On