Creating a hyperlink to a Remote Desktop session

April 25th, 2012

I’ve been working on an internal server inventory tool with a focus on including one-click shortcuts and other such tricks. What I wanted to do here today was to allow a user to connect to the listed server via Remote Desktop (RDP) with as much ease as possible.

I decided I’d take the approach of using an RDP file. I created a session using mstsc.exe and saved it to my disk. I opened the file in a text editor to see what was going on:


screen mode id:i:2
use multimon:i:0
desktopwidth:i:1680
desktopheight:i:1050
session bpp:i:32
winposstr:s:0,1,2213,277,3265,1015
compression:i:1
keyboardhook:i:2
audiocapturemode:i:0
videoplaybackmode:i:1
connection type:i:2
displayconnectionbar:i:1
disable wallpaper:i:1
allow font smoothing:i:0
allow desktop composition:i:0
disable full window drag:i:1
disable menu anims:i:1
disable themes:i:0
disable cursor setting:i:0
bitmapcachepersistenable:i:1
full address:s:woslabfiles
audiomode:i:0
redirectprinters:i:1
redirectcomports:i:0
redirectsmartcards:i:1
redirectclipboard:i:1
redirectposdevices:i:0
redirectdirectx:i:1
autoreconnection enabled:i:1
authentication level:i:2
prompt for credentials:i:0
negotiate security layer:i:1
remoteapplicationmode:i:0
alternate shell:s:
shell working directory:s:
gatewayhostname:s:
gatewayusagemethod:i:4
gatewaycredentialssource:i:4
gatewayprofileusagemethod:i:0
promptcredentialonce:i:1
use redirection server name:i:0
drivestoredirect:s:

Now obviously, I don’t need to impose all these options on a user. Thought I’d try to pare this down to bare necessities:


full address:s:woslabfiles

This single line, saved as a *.rdp file, will open a session to the listed address, which in my case was the intranet computer at short name woslabfiles.

Now we have about a thousand machines, and we add new ones regularly, so there’s no way I’m interested in making an RDP file for each. I need to generate these on the fly. The inventory I’m building is in a Microsoft MVC architecture, so sharing this code should be really short & straightforward.

I added a method called RDP to my controller that will handle spitting out the on-the-fly *.rdp. No real trick here, just some HTTP headers to tell the browser to download the file rather than open it inline.


namespace Inventory.Controllers
{
public class ItemController : Controller
{
public PartialViewResult RDP(int id)
{
// Load the server model
Item item = db.Items.Find(id);

// Make a filename out of the server name
String filename = item.Name + ".rdp";

// Set the MIME type and other appropriate HTTP headers
Response.AddHeader("Content-type", "application/octet-stream");
Response.AddHeader("Content-Disposition", ("attachment; filename=" + filename));
Response.AddHeader("Pragma", "no-cache");
Response.AddHeader("Expires", "0");

// Return the view file.
return PartialView(item);
}
}
}

And the PartialView file the controller returns—RDP.cshtml—is almost as short as the one-line *.RDP file above:


@model Inventory.Models.Item

full address:s:@Model.Name

I added a simple link to the controller in my server drill-down page:

A little styling in the CSS, with an icon:


.RdpLink { float: right; background: url(../images/rdp.png) top center no-repeat; }
.RdpLink a { display: block; padding-top: 50px; }

Voila!

Screen grab of RDP link / icon

Showcase Home Hardware

December 2nd, 2009

Showcase Home Hardware is a home hardware store interfacing an all-in-one business solution, NetSuite, with my own scratch-built store front.  I headed up all the development with plenty of consultation from the store’s owner (trying to fit locksets into a standardized data structure), a UI expert (lots of input on the configurator and general layout/interface), and an SEO expert (black magic, no doubt).

Seven Tricks Web Users Don’t Know

November 17th, 2009

Because sometimes it’s easy for us robots to lose touch with how real people use computers:
Seven Tricks Web Users Don’t Know

Baby Heads

May 6th, 2009

This site was built to sell original hand-made glass Baby Heads by Oliver Doriss at Fulcrum Gallery.