Experimental Life!

Thursday, February 21, 2013

Automating the retrieval of MSDN Product keys

I know it can be a pain if you want to get all the product keys from MSDN subscription. With the new MSDN restrictions of key requests, one can get a maximum of 10 keys per day.

As a subscriber, I would like to have access to all my keys and I don’t agree with Microsoft on the key misuse prevention tactics. During the earlier years, I used to get all the keys at one shot, export them to an Excel document, have it printed and stuck to my wall for easy reference. Though I don’t use all the available keys, some where used frequently like OS installation keys etc., Mostly in an virtualized environments. But now, I can request only 10 keys per day and I have remember to do it every day religiously and with an exact time gap of 24 Hours+). Even if I schedule a reminder, some times it might not be possible to perform the operations due to other constraints and once the time exceeds 24 hours, it delays the fore coming day’s request by the current delayed period. I guess you understand me. (Hmmm. why would you visit my page anyways if you don’t! :D)

Ok. ranting apart, what would be the best way to automate the downloading of all keys (at least 10 per day but at regular intervals and without any human intervention)?

Well, the following is the solution created by me. I created a simple VBScript and a very small C program to automate the requesting of MSDN Keys.

Pre-requisites:

  • Windows System with Internet Explorer 8 (minimal and be it a Windows XP or 2003 for easier IE Automation! Sorry Windows 7 & 8!) with Silver light installed and working
    • N.B.: I have not tested the solution on a Windows 7 (IE 9 and above). The solution was tested on XP and on IE8. Please forgive me for that.
  • Open TWebst framework installed from http://open-twebst.codecentrix.com/ (I have tested with the version 1.1.0.0)
  • VBScript file (GoToMSDN.vbs) as provided below
  • A really small executable (Only 511 bytes compressed) (MyTinyScheduler.exe) (Available at: http://www.mediafire.com/?6yuyt834nz64x3r as a RAR compressed file!!!) If your antivirus flags it as suspicious, please compile yourselves from the source code!!! Please request for the source code and I am happy to provide it! I might actually add it to the post if the requests are high!
    • MyTinyScheduler.exe Program Description: It is a simple scheduler specifically created for this purpose which would launch the script at a 24 Hrs + 5 minutes increment day by day. You could easily create a delayed launcher yourselves either by using a Power shell script or even by using a simple batch script!!! Experiment!!)

VBScript: (to be named as GoToMSDN.vbs)

'Use the command line below to launch the script (or just double click the .vbs file):
' %windir%\system32\wscript.exe GoToMSDN.vbs

Option Explicit
Dim core
Dim browser
Dim iLoop

Set core    = CreateObject("OpenTwebst.Core")  ' creates the OpenTwebst Core Object

Set browser = core.StartBrowser("https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1360563667&rver=6.0.5276.0&wp=MCMBI&wlcxt=msdn%24msdn%24msdn&wreply=https%3a%2f%2fmsdn.microsoft.com%2fen-us%2fsubscriptions%2fkeys&lc=1033&id=254354&mkt=en-US") ' Navigates to the URL for login

Call browser.FindElement("input text", "id=i0116").InputText("<YOUR MSDN USERNAME>") ' Please replace <YOUR MSDN USERNAME> with your actual MSDN User Name
Call browser.FindElement("input password", "id=i0118").InputText("<YOUR MSDN PASSWORD>") ' Please replace <YOUR MSDN PASSWORD> with your actual MSDN Password
Call browser.FindElement("input submit", "id=idSIButton9").Click() ' Logs into the account
WScript.Sleep(30000) ' A sleep to make sure that the product keys page is loaded for slower networks! Does not harm in anyway!
For iLoop = 0 to 15 'Just to make sure that it processes at least 10 clicks! Mostly it works without any issues.
    Call browser.FindElement("a", "uiname=Get Another Key, index=1").Click()
    WScript.Sleep(5000)
Next
Call browser.FindElement("a", "uiname=Sign out").Click() ' The logout click!!
WScript.Sleep(40000) ' A sleep to make sure that the account is signed out! For slower networks! Does not harm in anyway!
browser.Close() ' Closes the OpenTwebst Core Object and returns the control to the scheduler program!

Steps to follow:

  1. Please replace the <YOUR MSDN USERNAME> and <YOUR MSDN PASSWORD> with your actual MSDN User name and Password!
  2. Create a folder in C:\> Drive called Automation, such that the path will be C:\Automation>. Copy all the files GoToMSDN.vbs and MyTinyScheduler.exe to the folder. If you would like to create a power shell or a batch file, just replace the directory appropriately.
    • For example to call the script from a batch file, you could use the “%windir%\system32\wscript.exe C:\Automation\GoToMSDN.vbs” command
  3. Just double click the MyTinyScheduler.exe and enjoy the key automation until all the keys are requested. By default, the program will execute everyday and request the keys (a maximum of 10 keys on your behalf), until the machine is shutdown or the MyTinyScheduler process is killed manually.

Once in a while, log into your account, export the keys and safeguard it!! As simple as it sounds!!

Happy hacking and tinkering!!

No comments: