Passing Arguments_thumb.jpg 1From time to time I’m writing Windows Batch files and it’s quite useful to know how to pass arguments to a Windows Batch file, for example so you can modify selected items.

Let me give you an example. Assume you have multiple files (text files or images, whatever) and you select them, now you want to run a batch file on all selected files. How would you do that? Sure you could hardcode it, but that’s not very practical if the file names changes. Luckily, Windows batch files support arguments.

Click here to join - Rare NFTs and Play-to-Earn Games or Read my review first!

Let’s pass some arguments to the batch file and then launch it via context menu.

1. Step Open regedit.exe
2. Step Uncollapse HKEY_CLASSES_ROOT\*\shell\
3. Step Create a folder called OperationTest, create subfolder called command (If you need more help with this, please read our tutorial how to add new items to Windows context menu where we explain the entire process)
4. Step On the right pane create a registry “String Value” (REG_SZ) and enter this:

C:\scripts\mycoolfile.bat %1

Passing Arguments 1

The %1 will now pass on all selected files. Handy, eh?

In a test batch file simply enter echo %1 and you will see that it is storing the entire path to the files to all selected files in the variable %1 – you can now modify the variable %1 using the common batch operations

I hope this will help you to create some really cool Windows Batch files that will boost your productivity or whatever you want to do.