MediumLeveraging “Despacito” in a Corporate Environment | by Filipp Kay | Medium
Sitemap

Leveraging “Despacito” in a Corporate Environment

How to get your feet wet with client-side programming in VBS

--

Press enter or click to view image in full size

Every now and then, a company experiences mild logistical adjustments to keep its branding and company face consistent with its internal policies. Part of that, invariably, is changing your email domain every few years for posterity. Unfortunately for said company, the clientele takes a while to catch up, and often sends mail (understandably) to the old email domain. Usually, the best practice is to continue monitoring it, but responding from your new domain while making sure employees don’t accidentally send replies from the old email domain.

Get Filipp Kay’s stories in your inbox

Join Medium for free to get updates from this writer.

I, however, am a professional with standards, and part of those standards includes having a good time at nobody’s expense. While I could write code on a firewall that simply reroutes replies from the old email domain to the empty black void of cyberspace parked conveniently behind the employee lounge, I decided to have a little fun with the endeavor. I set up an event trigger in some of my coworkers’ Outlook profiles that watches for outgoing emails, inspects the email address, and punishes them by playing “Despacito” by Luis Fonsi for about 4 minutes in an invisible browser window. The programming language in question was Visual Basic, which is only appropriate for an application whose sole purpose is to cause indescribable agony to the user.

The Man, The Myth, The Source Code

const despacito = "https://vimeo.com/271784656"
const icon = "play-icon"
dim sAPI, ie, playButton
set sAPI = CreateObject("SAPI.SpVoice")
set ie = CreateObject("Internetexplorer.application")
ie.visible = false
ie.navigate (despacito)
do while ie.readyState <> 4 : wscript.sleep 1000 : loopsAPI.speak "I just opened up despacito on your computer, you coward. Stop sending emails from your old domain."set playButton = ie.document.getElementsByClassName(icon)(0)
playButton.click
wscript.sleep (1000 * 60 * 4) + (40 * 1000)
set ie = nothing

If you’re already familiar with VBScript, then this should probably be pretty straightforward. If you program in literally any other language, then this is probably the part where you stopped reading. Otherwise, you probably have some questions about what’s going on up there.

const despacito = "https://vimeo.com/271784656"
const icon = "play-icon"
dim sAPI, ie, playButton

dim, or “Declare in Memory” if you’re not in a hurry, is how you inform your computer that you’re about to use variables with the names sAPI, ie, and playButton. Your computer, after rolling it’s eyes at you, begrudgingly takes this into account. Const, or Constant, is a variable whose value can never change. Pretty easy stuff.

set sAPI = CreateObject("SAPI.SpVoice")
set ie = CreateObject("Internetexplorer.application")
ie.visible = false
ie.navigate (despacito)

This is the part where you summon the eldritch being that is Internet Explorer 11, as well as Microsoft’s speech API by using the CreateObject() function. We’re going to use the speech API to mock our end user, and utilize IE11 for the finishing blow of playing Despacito after we navigate to the Vimeo URL. Setting IE11’s visible property to false ensures that browser window stays hidden for the duration of the experience.

do while ie.readyState <> 4 : wscript.sleep 1000 : loopsAPI.speak "I just opened up despacito on your computer, you coward. Stop sending emails from your old domain."

Here, we wait for the website to load by going through a do-while loop. If you’re new to programming, this simply means that we do the same thing over and over as long as something is true. In this case, it’s that IE11 isn’t “ready” because the page hasn’t loaded. Shortly afterwards, we alarm the end user by informing them that their suffering is about to begin.

set playButton = ie.document.getElementsByClassName(icon)(0)
playButton.click
wscript.sleep (1000 * 60 * 4) + (40 * 1000)
set ie = nothing

Smooth sailing from here on out. Scrape the Vimeo HTML code for the “play button” by looking for its class name — which was creatively titled Play-Button. After clicking play, we wait for about 4 minutes, and close the browser window. Are your ears bleeding? That’s fine.

Closing Remarks

Needless to say, my coworkers were very enthused after the musical stylings of Luis Fonsi and Daddy Yankee plagued their computers when they replied from the wrong email. In fact, they were so pleased with the experience they asked me if I could customize the song that plays when the trigger activates. Programming is, and ought to be, an enjoyable activity that leverages the creative power of the human condition. While everything from NASA to the NYSE runs with the help of diligent programmers who have spent decades perfecting their craft, the space magic of computer science doesn’t happen overnight. Everyone needs to start with basics, and there’s no better way to do so than by making everyone listen to the most overplayed song in the universe.

--

--

Filipp Kay
Filipp Kay

Written by Filipp Kay

0 followers

Software Engineer with a Master's in Data Science and a strong propensity for pushing programming to its absolute limits. Also a notorious gym rat.