Windows: How to add batch-script action to Right Click menu

06
2013-12
  • ervingsb

    I have a few programs that creates temp files or backup files or similar files that are not important. For example, GVim for Windows by default creates a backup file in filename.txt~.

    I sometimes need to clean up a dir and remove all these files. I have made a simple .bat file for this. However, it is cumbersome to have to start up cmd, navigate to the folder, run the script. Especially since this is a script that I would like to run often on various folders. And I do not want to copy the script to multiple folders, as this would be a maintenance nightmare.

    So, I was thinking, that the best solution would be to add a Right Click menu item that allows me to run the script. So that I can right click on a folder in Explorer and click Cleanup and then have my script run on this folder.

    So my question is: How do I add a right click menu action that runs a custom batch script?

  • Answers
  • Alex Essilfie

    I have tried on Windows XP SP3 with this .reg key. Don't have Windows 7 at the moment to test it properly but it should be almost the same.

    1. Open notepad and paste the code from below.
    2. Edit as per your need.
    3. Save as MyScript1.reg
    4. Double click to import in registry.
    5. Test by Right click on any directory in Explorer
    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\Directory\shell\MyScript1]
    @="Execute MyScript1"
    
    [HKEY_CLASSES_ROOT\Directory\shell\MyScript1\command]
    @="\"C:\\MyScriptsDirectory\\MyScript1Directory\\MyScript1.bat\" \"%1\""
    

  • Related Question

    Adding items to a files right click menu in Windows Explorer
  • Fire Lancer

    What do I need to do to add an item to the right click menu for files with certain file extensions, along with sub menus?

    An example would be adding items to run Python files (.py, .pyw, .pyc) with a specific version of Python, so the menu for a .py files would look like say:

    Open  
    7-Zip >  
        ...7zip stuff
    Run >  
        Python 2.5  
        Python 2.6  
        Python 3.1  
    Edit >  
        IDLE 2.5  
        IDLE 2.6  
        IDLE 3.1  
    various other items
    

  • Related Answers
  • 8088

    FileMenu Tools can help you create extra items in the context menu of Windows Explorer, including sub-menus. You can add the extra items only for some extensions or type of elements (files, drives, folders, ...).

    alt text

  • heavyd

    In Windows XP (other Windows' should be similar):

    1. Open the File Types configuration dialog (in an explorer window Tools->Folder Options, File Types tab)
    2. Select the Registered file type you would like to add an item for
    3. Select the "Advanced" button under the "Details for ... extension" box
    4. Create a new action and associate it with the command line you would like to run.

    That should add an item to the context menu for that file type.