Saturday, February 6, 2010

Stupid shortcut tricks, or how to get an elevated shortcut to open a command prompt window in the SharePoint root folder on 2008 R2...

So I'm writing the SPF book, and I always create a shortcut to the SharePoint hive (now called SharePoint root) BIN folder on my SharePoint VM so I can quickly get to STSADM if I need it.

I tried to do so this time (in a hurry and not expecting problems), and I ran across a "known feature" of 2008 R2, where if you create a shortcut for the command prompt, and have it start in the long path to the BIN folder, it will work-- as long as you don't set it to run with elevated privileges (and STSADM won't run in a command prompt, regardless of your login, unless you run it as administrator). If you set the cmd.exe shortcut to run with elevated privileges-- it always only starts in the system32 folder. That's supposed to be safer.

Safer?  To specifically open to the system32 folder if you are running an elevated command prompt? Wouldn't it be safer to have an elevated prompt open many other folders than system32?

Am I missing something?

But, regardless of that shortcoming, I still need a quick way to get to the BIN folder from the desktop.

So here's what I did...

...I created a batch file that opens the command prompt to the correct path, then a made a shortcut to that, and set the shortcut to run as administrator.

To do the batch file, I just used notepad, saved the file with the BAT extension (make sure you don't have hide extensions on, or the file will have a hidden TXT extension) - then I typed in notepad:
@echo off
cmd /k cd "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN"

Then I saved the file and closed it.

Then I made a shortcut of it (right clicked it and selected create shortcut). Then, to set the shortcut to run with elevated privileges, I right clicked it, went to properties on the popup menu. In the dialog box, on the shortcut tab, I clicked the Advanced button, then selected "Run as administrator". then I clicked OK to save the change, and OK again to close.

Now all I've got to do to get a command prompt that is running as administrator and starting in the BIN folder, is double click the shortcut.

Just thought you should know in case it happens to you.