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!
You can try with shortcutjs.bat
call shortcutjs.bat "some.lnk"^| find /i "target:"
Like vbscript this also uses windows script host , but with the other built-in language - jscript , but wrapped in a .bat
file. Extracting the target will be not possible with pure batch.