1
如何从Windows批处理文件中的快捷链接提取路径而不使用vbscript?从快捷链接提取路径 - windows批处理
如何从Windows批处理文件中的快捷链接提取路径而不使用vbscript?从快捷链接提取路径 - windows批处理
您可以使用wmic
查询到win32_shortcutfile。只要确保你所有的反斜杠都在%filename%
内反斜杠转义。
语法:
batfile shortcutfile.lnk
代码:
@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!
call shortcutjs.bat "some.lnk"^| find /i "target:"
如VBScript这还使用Windows脚本宿主尝试,但与其他内置语言 - JScript中,而是裹在.bat
文件。提取目标将无法使用纯批处理。