Thursday, June 28, 2007

HowTo: Add cmd.exe to right click context menu

If you want the command prompt to be available whenever you right click on objects on your desktop or explorer, you can opt to create the keys in the registry:

  • HKEY_CLASSES_ROOT\Folder\shell\MenuText\Command

Change the (Default) value to cmd.exe /k cd "%1"

Or you can script it!

Code Snippet:
  1. Const HKEY_CLASSES_ROOT = &H80000000
  2. Const HKEY_CURRENT_USER = &H80000001
  3. Dim WSHShell, objWMIService, strComputer, lcValue1
  4. strComputer = "."
  5. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  6. Set objWSHShell = WScript.CreateObject("WScript.Shell")
  7. Set objRegObj = WScript.CreateObject("RegObj.Registry")
  8. objWSHShell.Popup "This will enable CMD with explorer options for the Current User"
  9. objWSHShell.RegWrite "HKCR\Folder\Shell\MenuText\Command\", "cmd.exe /k cd " & chr(34) & "%1" & chr(34)
  10. objWSHShell.RegWrite "HKCR\Folder\Shell\MenuText\", "Launch CMD"
  11. tmp = objWSHShell.RegRead("HKCR\Folder\Shell\MenuText\")
  12. objWSHShell.Popup ("Current Value: " + tmp)

If at first you fail, call it version 1.0

No comments: