navigation
 Wednesday, January 24, 2007

.NET 3.0 has a number of command line utilities like the service utility (svcutil.exe) that can be awkward to run if you're already in Explorer, deep in a folder structure.  Phillip's svn blog reminded me of a trick with the registry to get the command prompt window populated with the current path.

30netprompt.gif

You can use this technique for any command line or batch file you want to attach to the Explorer context menu. 

  1. Add a key (any name and content appears to work) to HKEY_CLASSES_ROOT\Folder\shell.
  2. Below that add a key "command" and set the text to be whatever command you want executed.  I copied the command line from the .NET 3.0 SDK "CMD Shell" (see registry export listing below), but you could use any command line entry.  The nice thing about the .NET 3.0 cmd shell is that it sets the environment so you can access svcutil.exe and other 3.0 specific utilities.

Registry export listing:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Folder\shell\Command Prompt]
@=".NET 3.0 Command Prompt"

[HKEY_CLASSES_ROOT\Folder\shell\Command Prompt\command]
@="C:\\WINDOWS\\system32\\cmd.exe /E:ON /V:ON /T:0E /K \"C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0\\Bin\\SetEnv.Cmd\""

Built in to Windows Vista

If you're running Vista then you're in luck, it's built-in!  Check out this article showing how to shift-right-click a folder to get the "Command Prompt Here" context menu item:

http://blogs.msdn.com/tims/archive/2006/09/18/windows-vista-secret-1-open-command-prompt-here.aspx