Randomly Opening CD Tray
- Posted: Oct 31, 2006 at 10:46 PM
- 7,712 Views
- 12 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
|A simple prank that opens the CD-ROM drive at random intervals.|
Time Required: Less than 1 hour
The best April Fools' Day pranks are those that can be enjoyed by both the fooler and the foolee. This short article covers one of the simpler pranks in the "Why is my computer doing that?" category: the malfunctioning CD-ROM drive that opens at random intervals. This prank is best used in a cube farm where multiple instances can be easily deployed and monitored.
The prank itself is very simple: a little program that, once launched, waits n minutes, then opens the CD-ROM drive door. It then continually opens the door at random intervals until the user closes the application. (Both n and the random interval constraint can be modified by the fooler via the application's config file.)
The most difficult part of the prank is getting the application onto the foolee's computer.
I've recently begun using the Google Web Accelerator, which speeds up your Web browsing. Or so they say. The only indication that it is doing anything is a report of how much time it has saved me:
If you're reading this article, you probably have an idea how the Accelerator works. However, 99 percent of its users don't. They take its word that it's working, and this trust is a primary component of our evil deed.
Our prank appears to be similar to the Web Accelerator. Once launched, it sits in the notification area until the user closes it. Unbeknownst to the user, the Web Speedster is the source of the randomly opening CD-ROM drive door. The initial CD-ROM door opening is delayed so the foolee doesn't make the connection with the Speedster.
The application itself is tiny — less than a dozen lines of code. The most interesting part is how the door is opened, since the .NET Framework doesn't natively provide this functionality.
The .NET Framework has almost everything most people need to create great applications, but sometimes developers need to access unmanaged functionality provided by other libraries, including Windows itself. Platform Invoke, or P/Invoke, is the gateway to these libraries. Methods in other libraries are defined with external method declarations like the following, which lets us call the mciSendString method in Windows WinMM DLL:
static extern Int32 mciSendString(String command, StringBuilder buffer, Int32 bufferSize, IntPtr hwndCallback);
Declare Function mciSendStringA Lib "winmm.dll" (command As String, _
buffer As StringBuilder, bufferSize As Int32, hwndCallback As IntPtr) As Int32
(PInvoke.NET is a great resource for finding these declarations.)
Calls to these methods are done just like calls to "normal" methods:
mciSendString("set CDAudio door open", null, 0, IntPtr.Zero);
And that is all that's required to make a function call into Windows. Easy!
While the .NET Framework is huge, it doesn't do everything. However, if Windows can do what you need, chances are very good that you can get to that functionality with P/Invoke.
The next step is to compile the program, send it out to unsuspecting foolees (ideally within earshot), and let the fun begin!