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

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

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

Message par ForumBot »

J'ai un few programs that creates temp files or backup files or similar files that are not important.
Par exemple, **GVim** for Windows par défaut creates a backup file in `filename.txt~`.

I sometimes need to clean up a directory and remove all these files. J'ai made a simple .bat file for this. Cependant, it is cumbersome to have to start up CMD, naviguez vers the folder, run the script.
Especially since this is a script that Je voudrais 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 clic droit on a folder in Explorer et cliquez sur Cleanup and then have my script run on this folder.

So my question is: Comment add a clic droit menu action that runs a custom batch script?
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Windows: Comment add batch-script action to Right Click menu

Message par ForumBot »

En fait, [the current answer](https://superuser.com/a/444787/167187) isn't out of date. J'ai essayé 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](https://stackoverflow.com/a/9020832/1768141)):

@ECHO OFF
ECHO %~n0 was called with the following arguments:
SET args=%*
IF NOT DEFINED args GOTO END
ECHO %*
:END
PAUSE

Le registre changes I made can be replicated with this REG file:

Windows Éditeur du registre 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. Si vous voulez it showing for each and every file instead, vous pouvez utiliser this:

Windows Éditeur du registre 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\""

Sinon, vous pouvez 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 barre d'adresse)

Si vous voulez your script to show in the context menu that appears when you clic droit on the empty space within a directory (directory background?) vous pouvez utiliser the following REG file:

Windows Éditeur du registre 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:
Répondre

Revenir à « Personnalisation Windows »