如何在不使用 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!
关于batch-file - 从快捷方式链接中提取路径 - Windows 批处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43210443/