Windows: How to add batch-script action to Right Click menu
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Quiet Intelligence
--
Chapters
00:00 Windows: How To Add Batch-Script Action To Right Click Menu
01:02 Answer 1 Score 35
02:37 Accepted Answer Score 19
03:15 Answer 3 Score 15
03:55 Answer 4 Score 1
04:25 Answer 5 Score 0
04:52 Thank you
--
Full question
https://superuser.com/questions/444726/w...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#windows #windowsexplorer #batch
#avk47
ANSWER 1
Score 35
Actually, the current answer isn't out of date. I tried the exact same thing on Windows 10 and was able to add Run Batch script
to the context menu of all folders in Windows.
This is the content of my batch script (won't work with UNC paths):
@ECHO OFF ECHO %~n0 was called with the following arguments: SET args=%* IF NOT DEFINED args GOTO END ECHO %* :END PAUSE
The registry changes I made can be replicated with this REG file:
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\shell\Run Batch script] @="&Run Batch script" [HKEY_CLASSES_ROOT\Directory\shell\Run Batch script\command] @="\"H:\\BATCH_FILE_PATH\\context-batch.bat\" \"%1\""
This only adds a context menu item for all directories/folders in Windows. If you want it showing for each and every file instead, you can use this:
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\Run script] @="Run &script" [HKEY_CLASSES_ROOT\*\shell\Run script\command] @="\"H:\\BATCH_FILE_PATH\\context-batch.bat\" \"%1\""
Alternatively, you can add your batch script to the Send To
item list by creating a shortcut to your batch script and placing it under %APPDATA%\Microsoft\Windows\SendTo
(or enter shell:sendto
into the address bar)
If you want your script to show in the context menu that appears when you right click on the empty space within a directory (directory background?) you can use the following REG file:
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\Background\shell\Run Batch script] @="&Run Batch script" "Icon"="%SystemRoot%\\System32\\shell32.dll,71" [HKEY_CLASSES_ROOT\Directory\Background\shell\Run Batch script\command] @="H:\\BATCH_FILE_PATH\\context-batch.bat \"%V\""
You don't need the "Icon"="%SystemRoot%\\System32\\shell32.dll,71"
line. It simply adds an icon to your context-menu that looks like this:
ACCEPTED ANSWER
Score 19
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.
- Open notepad and paste the code from below.
- Edit as per your need.
- Save as MyScript1.reg
- Double click to import in registry.
- 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\""
ANSWER 3
Score 15
I would recommend Default Programs Editor for this task. It is both more user friendly and arguably safer than editing the registry directly.
Select the extension you want to change.
Give your command a Title, browse to the batch file and optionally pick an icon to represent your command.
Save the context menu to the registry and you're good to go.
ANSWER 4
Score 1
@Vinayak,
If using the "send to" option, you would probably need to add the line cd /d %1
to the start of the batch command so that it runs under the target path.
my current batch file looks like this:
@echo off
cd /d %1
del *.txt
pause
Thanks for the help, I happened to stumble upon this via google at the right time :)
ANSWER 5
Score 0
Alternative solution which I use on Windows 10 is adding script to one of folders in path variable, and then when you are in explorer use sequence:
ctrl + L - to start writing in search bar
type: cmd, then press Enter - to start cmd in current directory
run your script, by typing its file name