例如,我在 c:/PersonalPhotos/ 中有一个名为 tree.jpg 的图像文件
我把该文件拖到桌面上的某个批处理文件中
批处理文件读取文件输入并在新的目录中创建该图像文件的快捷方式(在此示例中,该目录为 d:/ScenaryPhotos/)
我以为读取文件的路径会很困难,但没关系(因为我只是用它作为开始https://stackoverflow.com/questions/44577446/),我只是停留在创建快捷方式部分,因为它需要 vb 脚本。
答案1
此批处理脚本在 %temp% 文件夹中创建一个临时 VBScript。这是预期结果吗?
@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
答案2
最简单的方法是使用近红外命令捷径:
在你的情况下(拖放),你应该使用"%~1"作为[文件名]
https://nircmd.nirsoft.net/shortcut.html
NirCmd 命令参考 - 快捷方式
快捷方式 [文件名] [文件夹] [快捷方式标题] {参数} {图标文件} {图标资源编号} {ShowCmd} {在文件夹中启动} {热键} 创建文件的快捷方式。参数:
[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
例子:
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"