Windows Messenger provides API for accessing some of its internal objects, e.g. enumerate the logged-on user's contact list. This API is exposed as a COM object, through the Messenger API Type Library (msmsgs.exe).
A major drawback of this API is that it lacks some basic functionality. For example, it is impossible to programmatically add a given user to the contact list without the need for user interaction (we can only launch the "Add a contact..." dialog box).
This article suggests a solution to this unfortunate issue, through the use of Windows Messenger Private APIs.
Windows Messenger's Private API
Windows Messenger has another set of APIs, which is probably intended for internal MS use only. This API is also exposed as a COM object, through the Messenger Private Type Library (msmsgs.exe). Among other things, the API provides the ability to programmatically add a user to the contact list, with no user interaction whatsoever.
However, attempting to use this API reveals that each and every method throws an exception, claiming that the object wasn't "unlocked". MSDN documentation explains that applications need to authenticate themselves in a challenge-response process, which requires the use of an ID / KEY pair. The latter might have been issued by MS in the past, but no more.
The attached C# source code package demonstrates how the private API can be unlocked.
The source code package consists of a single VS2003 project (console application) and two C# classes:
MessengerUnlocker unlocks a given
MessengerPriv object, by performing the challenge-response process. This is the nuts-and-bolts of this article.
MessengerUnlockerDemo is nothing but a
Main method that creates, unlocks and uses a
MessengerPriv object. To prove that the latter is indeed unlocked, a hard-coded user is added to the running user's contact list.
Source code is documented in a standard C# style. Here and there, the source links to external Internet sites for further explanations regarding the challenge-response process.
Make sure you have Windows Messenger installed, running and signed-in before running the demo.
Before running the demo a second time, remove the newly added user from the contact list. Attempting to add an already-added contact causes an exception to be thrown.
This code heavily relies on private and unsupported APIs, which are subject to change at any given moment (assessing the likeliness of the API actually changing in the future is left for the reader). This article is the product of my curiosity and free time. If you base your production code on this, you are mad.
The code was tested against Windows Messenger 4.7.3001, but might as well work perfectly against other versions of Windows Messenger (4.6 in particular). It would probably not work against MSN Messenger of any version.
Special thanks goes to http://www.hypothetic.org/docs/msn/, for their great documentation of the Messenger Protocol. These wonderful guys provided me with the last missing piece of the puzzle - a valid ApplicationId / ApplicationKey pair :)