Welcome to this tutorial on adding old contacts to a new MSN account. This tutorial explains the MessengerAPI COM object, and how we can use this API to make it easier to re-add all of our old contacts.
This process is dependent on the
AddContact() subroutine, which we shall be using here. In this tutorial, we will be making a Windows Form that we can use to create a simple GUI for the user to access and add contacts with ease. Lets get started!
1) Goto
File > New > Project.. and select
Windows Application. Set the Name to "msnAdder" or something simular, and click OK.
2) Set Form1's name property to
frmMain, and set the Text property to
Msn Contact Adder.
3) Add a CheckedListBox control to the form, and rename it to
chlContacts. Adjust both the Form and the CheckBox's size to look neater on the form.
4) Add two buttons to the top of the form,
btnGet and
btnSet. These buttons will give the option of getting the addresses, or setting the addresses into a new MSN account. Set the Text Properties to "Get" and "Set". Your form should now look like Figure 1.1:
Figure 1.1: What your form should look like now.
5) Now that we have the design set up, it's now time to add the MessengerAPI COM Object. Goto
Project > Add Reference.., and click the COM Tab above the list of components. Scroll down until you find Messenger API Type Library, select it and click OK.
Figure 1.2: The COM object we are looking for.
6) Now it's time to add the main object to the form. Double Click on the Get Event so we are in Code View. Just After "Public Class frmMain" and before the button press event, declare this variable:
CODE
Dim objMSN As New MessengerAPI.Messenger
This will create an instance of the
MessengerAPI.Messenger object so we can use it to access the MSN session.
7) Now that we have our main instance, we can now use the
btnGet button to get all the contacts the user would like to import into their new address. Copy and paste the following code into the btnGet.Click() event.
CODE
Dim msncontact As MessengerAPI.IMessengerContact
Dim msncontacts As MessengerAPI.IMessengerContacts = objMSN.MyContacts
' Get rid of anything in the list.
chlContacts.Items.Clear()
' Loop through all the contacts and add the SigninName to the list.
For Each msncontact In msncontacts
chlContacts.Items.Add(msncontact.SigninName)
Next
The code above will loop through all the contacts, and add all the MSN Addresses into a CheckBoxList which they will then decide whether they want to add this contact or not.
8) Now that we have the ability to get all the contacts, we can now add them all to our new account. (Note, the user will need to sign into his/her new account in-order to add the new contacts).
Copy and paste this code into the btnSet.Click Event:
CODE
For i As Integer = 0 To chlContacts.CheckedItems.Count - 1
objMSN.AddContact(0, chlContacts.CheckedItems.Item(i))
SendKeys.Send("{enter}")
Next
MessageBox.Show("The operation completed successfully.")
The code above will loop through all the Checked ListBox items, and add them to Messenger. An Enter KeyPress is sent to close the Add Contact window, and act as an Ok Button press.
9) Test your project.
I have yet to receive an error with this code, it has been tested with both my computer and my laptop, and I am sure there isn't any bugs with the coding. However, it is good practice to test it anyway.