2

For example I have an image file called tree.jpg in c:/PersonalPhotos/

I drag that file onto some batch file sitting on my desktop

The batch file reads the file input and creates a shortcut to that image file to a new directory (in this example this directory will be d:/ScenaryPhotos/)

I thought that reading the path of the file would be difficult but it's fine (as I'm just using this as a start https://stackoverflow.com/questions/44577446/), I'm just stuck at the creating shortcut part because it requires vb scripting.

  • 1
    so why is the vbs a problem? I'm assuming you are referencing this question? https://superuser.com/questions/392061/how-to-make-a-shortcut-from-cmd – Frank Thomas Nov 29 '21 at 20:43
  • So you want that if you drag and drop a photo from c:\PersonalPhotos\tree.jpg to the batch it should create a shortcut in d:\ScenaryPhotos\ that points to c:\PersonalPhotos\tree.jpg ? – Ricardo Bohner Nov 29 '21 at 22:03
  • @FrankThomas vbs is only a problem because i think it takes a bit to understand and use it, I understand that learning a language makes it simpler to learn other languages but I'm already new with bat/powershell so I 'm not sure how well i'd fare with vbs. – Jacobstacker Nov 30 '21 at 02:02

2 Answers2

2

This batch script creates a temporary VBScript in the %temp% folder. Would this be the expected result?

@echo off

if /i not exist "%~1" exit

set SDestination=d:\ScenaryPhotos

If /i not exist "%SDestination%" md "%SDestination%"
pushd "%SDestination%"

echo strTargetPath="%~nx1.lnk">"%temp%\tempvbs.vbs" 
echo Dim objShortcut, objShell>>"%temp%\tempvbs.vbs"
echo Set objShell = WScript.CreateObject ("Wscript.Shell")>>"%temp%\tempvbs.vbs"
echo Set objShortcut = objShell.CreateShortcut (strTargetPath)>>"%temp%\tempvbs.vbs"
echo objShortcut.TargetPath = "%~1">>"%temp%\tempvbs.vbs"
echo objShortcut.WorkingDirectory = "%SDestination%">>"%temp%\tempvbs.vbs"
echo objShortcut.Save>>"%temp%\tempvbs.vbs"
echo WScript.Quit>>"%temp%\tempvbs.vbs"

"%temp%\tempvbs.vbs"
del /q "%temp%\tempvbs.vbs"
exit

enter image description here

Ricardo Bohner
  • 3,903
  • 2
  • 18
  • 12
0

Easiest way is using NirCmd shortcut:

In your case (drag and drop), you should use "%~1" as [filename]

https://nircmd.nirsoft.net/shortcut.html

NirCmd Command Reference - shortcut

shortcut [filename] [folder] [shortcut title] {arguments} {icon file} {icon resource number} {ShowCmd} {Start In Folder} {Hot Key} Creates a shortcut to a file. The parameters:

[filename]: Create a shortcut to this filename.
[folder]: Specify the destination folder that inside it the shortcut will be created. You can specify any valid folder, including the special variables that represent system folders, like ~$folder.desktop$ (Desktop folder), ~$folder.programs$ (Start-Menu-Programs folder), and so on...
[shortcut title]: The text displayed in the shortcut.
{arguments}: Optional parameter - Additional arguments to execute the filename.
{icon file}: Optional parameter - Use this parameter if your want that the shortcut will be displayed with icon other than the default one.
{icon resource number}: Optional parameter - The resource number inside the icon file.
{ShowCmd}: Optional parameter - Use this parameter if you want to maximize or minimize the window of the program. Specify "max" to maximize the window or "min" to minimize it.
{Start In Folder}: Optional parameter - Specifies the "Start In" folder. If you don't specify this parameter, the "Start In" folder is automatically filled with the folder of the program you specify in [filename] parameter.
{Hot Key}: Optional parameter - Specifies an hot-key that will activate the shortcut. For example: Alt+Ctrl+A, Alt+Shift+F8, Alt+Ctrl+Shift+Y 

Examples:

shortcut "f:\winnt\system32\calc.exe" "~$folder.desktop$" "Windows Calculator"

shortcut "f:\winnt\system32\calc.exe" "~$folder.programs$\Calculators" "Windows Calculator"

shortcut "f:\Program Files\KaZaA\Kazaa.exe" "c:\temp\MyShortcuts" "Kazaa"

shortcut "f:\Program Files" "c:\temp\MyShortcuts" "Program Files Folder" "" "f:\winnt\system32\shell32.dll" 45

shortcut "f:\Program Files" "c:\temp\MyShortcuts" "Program Files Folder" "" "" "" "max"

DarkDiamond
  • 1,875
  • 11
  • 12
  • 19
amymor
  • 35
  • 8