How to pass a filename by drag-and-drop to a shortcut in Windows

16,186

Solution 1

Just use program.exe -param as a target in your shortcut. Document path (or whatever else you drop onto it) is appended by default.

Loosely related: You may also drop an item from explorer onto command line window - this may save you a lot of typing!

Solution 2

Make a batch file that'd call your target executable with -param and batch file's first parameter and then make shortcut point to that batch file.

Solution 3

I couldn't get it to work with a regular shortcut, but you might want to create a batch file instead. Use %1 in place of where you want the dropped file's path. E.g.:

"C:\path to utility\myUtility.exe" %1 -f -g
Share:
16,186

Related videos on Youtube

Kendall Frey
Author by

Kendall Frey

I am primarily a C# programmer, but also use JavaScript, and some other languages in my spare time. Website: http://kendallfrey.com

Updated on September 18, 2022

Comments

  • Kendall Frey
    Kendall Frey almost 2 years

    I have a program program.exe and a document document.txt, and to open the document, I can drag document.txt onto program.exe. So far so good. Now I want to call it with a command-line parameter -param so that the full command line is program.exe -param document.txt Unfortunately, I can't do this with drag and drop, so I need to fire up cmd and type in the command manually. This takes too long, and I need an easier way.

    How can I create a shortcut that I can drop the file onto, and have it call the program with the command-line parameter?

    I tried setting the shortcut to program.exe -param "%1", but that didn't work, because it tried to open the file %1.

  • Ray
    Ray about 3 years
    You can simply drag files on batch files aswell, they will be passed as quoted paths the same way - however, since the batch file is no longer run in the directory it is stored in, you may want to CD %~dp0 at the start of it to switch to the batch directory first.