从快捷方式链接中提取路径 - 窗口批处理

Sta*_*ish 3 batch-file

如何在不使用vb​​script的情况下从Windows批处理文件中的快捷方式链接中提取路径?

roj*_*ojo 6

您可以通过wmic查询win32_shortcutfile完成此操作.只需确保所有反斜杠都在内部进行反斜杠转义%filename%.

句法:

batfile shortcutfile.lnk
Run Code Online (Sandbox Code Playgroud)

码:

@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!
Run Code Online (Sandbox Code Playgroud)