How can I extract the path from a shortcut link in windows batch file without using vbscript?
You can do it with a wmic
query to win32_shortcutfile. Just make sure all your backslashes are backslash-escaped within %filename%
.
Syntax:
batfile shortcutfile.lnk
Code:
@echo off
setlocal
rem // ensure user supplied a filename with a .lnk extension
if /i "%~x1" neq ".lnk" (
echo usage: %~nx0 shortcut.lnk
goto :EOF
)
rem // set filename to the fully qualified path + filename
set "filename=%~f1"
rem // get target
for /f "delims=" %%I in (
'wmic path win32_shortcutfile where "name='%filename:\=\\%'" get target /value'
) do for /f "delims=" %%# in ("%%~I") do set "%%~#"
rem // preserve ampersands
setlocal enabledelayedexpansion
echo(!target!