Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

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\""
share|improve this answer
2  
I've edited your answer a bit. "Windows Registry Editor Version 5.00" is mandatory 'header' for .reg files. Otherwise Windows will refuse to inject the contents into registry. –  extremko Jul 4 '12 at 10:48
    
+1 for pointing that one out. I totally forgot about that when c/p code. –  Robert Schmidt Jul 4 '12 at 11:49
    
@Alex: Thanks for the edit, I appreciate it. –  Robert Schmidt Jul 5 '12 at 11:05
    
I tried this. Now I can rightclick directyly on a folder, but it does not work if I rightclick inside a folder. Which is actually what I want. How to do that? –  ervingsb Jul 9 '12 at 19:49
    
That's a different question than the "So that I can right click on a folder in Explorer and click Cleanup and then have my script run on this folder." –  Robert Schmidt Jul 10 '12 at 9:29

Have you tried this: http://www.howtogeek.com/howto/windows-vista/add-any-application-to-the-desktop-right-click-menu-in-vista/

share|improve this answer
    
It's helpful to see the step-by-step screen shots in that article. However I think the HKEY_CLASSES_ROOT\Directory\Background\shell referenced there is for when you click on a blank area, not on a folder. The answer by @RobertSchmidt uses HKEY_CLASSES_ROOT\Directory\shell which is when you click on a folder (directory). See this MSDN article. –  Mark Berry Jul 2 at 16:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.