Recently I’ve been exploring the possibilities of MSBuild in my projects. MSBuild is a command-line tool so this involved spending a lot of time at the Visual Studio 2008 Command Prompt. And having to change directories every time I started a new instance really started getting on my nerves. So, Google to the rescue!

I found plenty of posts on the subject but none of them seemed to work for me. So, I modified the one I found here (thanks devsuldier!). Here are the steps to add the VS2008 Command Prompt to the context menu:

1. Using Notepad, create a file called “VS2008Cmd.reg”. Mind the extension!
2. Copy-paste the following lines into the file:

Windows Registry Editor Version 5.00 
 
[HKEY_CLASSES_ROOT\Directory\Background\shell\VS2008 Command Prompt]
@="Open VS2008 Command Prompt Here"
"Extended"=""
"NoWorkingDirectory"=""
 
[HKEY_CLASSES_ROOT\Directory\Background\shell\VS2008 Command Prompt\command]
@="C:\\Windows\\System32\\cmd.exe /s /k \"cd \"%1\" && \"C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\vcvarsall.bat\"\" x86 "
 
[HKEY_CLASSES_ROOT\Directory\shell\VS2008 Command Prompt]
@="Open VS2008 Command Prompt Here"
"Extended"=""
"NoWorkingDirectory"=""
 
[HKEY_CLASSES_ROOT\Directory\shell\VS2008 Command Prompt\command]
@="C:\\Windows\\System32\\cmd.exe /s /k \"cd \"%1\" && \"C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\vcvarsall.bat\"\" x86 "
 
[HKEY_CLASSES_ROOT\Drive\shell\VS2008 Command Prompt]
@="Open VS2008 Command Prompt Here"
"Extended"=""
"NoWorkingDirectory"=""
 
[HKEY_CLASSES_ROOT\Drive\shell\VS2008 Command Prompt\command]
@="C:\\Windows\\System32\\cmd.exe /s /k \"cd \"%1\" && \"C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\vcvarsall.bat\"\" x86 "

3. Save the file. Double-click the file to add the entries to the registry.

Now, when you Shift+Right-Click on a folder you can select the Visual Studio 2008 Command Prompt. Sweet!

Visual Studio Command Prompt

As a side-note, I ran into the problem that my current workplace resets the registry after rebooting. Annoying as hell, but luckily it’s not difficult to create a little startup script to add the entries to the registry every time I boot up:

1. Create a new file “AddVS2008Cmd.bat”. Again, mind the extension.
2. Copy-paste the following lines into the file:

@echo off
@echo -- Adding Visual Studio 2008 Command Prompt to the Explorer Context Menu
regedit.exe /s "VS2008Cmd.reg"

3. Add a shortcut to the Startup folder. To do this, navigate to Start > All Programs, right-click on the Startup folder and select Explore All Users. Then drag the AddVS2008Cmd.bat file to that folder holding Alt key.
4. Set the shortcut to start minimized. This is purely aesthetics. Right-click on the shortcut, select Properties and change the Run property to Minimized.

Please note that the above paths are only applicable if you are running an English language OS and if you have installed VS to the default location. If you are either running an other language OS or have installed VS to a different location you’ll need to update the paths above. Thank you very much Fritz for pointing this out.

That’s all there is to it. I hope you’ll find this as much of a time-saver as I have.

If you liked this post, please click on one of the advertisements below. Thanks!


16 Responses to “Adding the Visual Studio 2008 Command Prompt to your Explorer Context Menu”

  1. 1 Dan

    Sweet! Thanks man…

  2. 2 Gerardo

    Really cool. I can now run my build scripts in a snap.

  3. 3 Erik Burger

    @Dan: No problem. I hope it’s as much of a timesaver for you as it is for me.

    @Gerardo: Exactly what I intended it for! Saves me tons of time :)

    Regards,

    Erik

  4. 4 sumant

    i recieve a msg “registry entry has been disabled bu the user administrator”…
    it flashes for a second only
    pl tell an optimal sol to it

  5. 5 Erik Burger

    Hi Sumant,

    I’m afraid this means that you are not allowed to change the registry. Typically as a developer you are at least a local admin. The best solution I can offer you is to talk to your administrator about this.

    Erik

  6. 6 Fritz Kreh

    For non English windows installations, the path has to be adjusted (replace “program files” by local name). The same applies if VS is not installed to the default path.

  7. 7 Erik Burger

    You are absolutely right Fritz. I’ll update the post to include this note.

    Regards,

    Erik

  8. 8 James

    I followed this example on Windows XP but it doesn’t appear in the menu. Not sure what went wrong

  9. 9 Erik Burger

    Hi James,

    It might be that the version of the Windows Registry Editor is different on Windows XP. Are the registry keys actually created? If not, you could try creating them by hand.

    Best Regards,

    Erik

  10. 10 vikas Gupta

    How to do Same with VS2010?

  11. 11 Dean

    To convert to VS2010 simply replace

    VS2008 with VS2010
    Visual Studio 9.0 with Visual Studio 10.0

  12. 12 bobby

    Thnks for this but it doesnt seem to work on windows 7 64bit.. ??

  13. 13 Erik Burger

    It might be that replacing \\Program Files\\ with \\Program Files (x86)\\ will do the trick for you. Just check whether the paths are correct.

  14. 14 Erik Burger

    Garret Thomson left the following remark.

    Note that you probably want to add /D to the cd command, in order to make this work as intended on paths located on drives other than the Windows drive.

    I couldn’t post to the blog entry as I’m behind a proxy at work.

    Thanks Garret!

  15. 15 Thomas Hanks

    From the above suggestions, this works on windows 7 on any drive

    >>>>>>>>>> BEGIN .reg file >>>>>>>>>>
    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\Directory\Background\shell\VS2008 Command Prompt]
    @=”Open VS2008 Command Prompt Here”
    “Extended”=”"
    “NoWorkingDirectory”=”"

    [HKEY_CLASSES_ROOT\Directory\Background\shell\VS2008 Command Prompt\command]
    @=”C:\\Windows\\System32\\cmd.exe /s /k \”cd /D \”%1\” && \”C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\

    \vcvarsall.bat\”\” x86 ”

    [HKEY_CLASSES_ROOT\Directory\shell\VS2008 Command Prompt]
    @=”Open VS2008 Command Prompt Here”
    “Extended”=”"
    “NoWorkingDirectory”=”"

    [HKEY_CLASSES_ROOT\Directory\shell\VS2008 Command Prompt\command]
    @=”C:\\Windows\\System32\\cmd.exe /s /k \”cd /D \”%1\” && \”C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\

    \vcvarsall.bat\”\” x86 ”

    [HKEY_CLASSES_ROOT\Drive\shell\VS2008 Command Prompt]
    @=”Open VS2008 Command Prompt Here”
    “Extended”=”"
    “NoWorkingDirectory”=”"

    [HKEY_CLASSES_ROOT\Drive\shell\VS2008 Command Prompt\command]
    @=”C:\\Windows\\System32\\cmd.exe /s /k \”cd /D \”%1\” && \”C:\\Program Files\\Microsoft Visual Studio 9.0 (x86)\\VC\

    \vcvarsall.bat\”\” x86 ”
    <<<<<<<<<< END .reg file <<<<<<<<<<

  16. 16 Erik Burger

    Thanks very much Thomas, great work.

    Erik

Leave a Reply


*