batch-file - 从快捷方式链接中提取路径 - Windows 批处理

标签 batch-file

如何在不使用 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/

相关文章:

java - 使用 JNLP/Webstart 打开文件

php - 使用批处理文件中的参数运行exe文件

windows - 从单个批处理文件启动多个 shell 提示符

batch-file - CMD IF EXIST 带变量

batch-file - 循环遍历批处理文件中的 ASCII 代码

c#无法终止进程

batch-file - 去除文件名中定界符后的所有字符

powershell - 如何将PowerShell输出设置为批处理变量?

powershell - 批处理脚本可以知道它是否是从 PowerShell 调用的吗?

regex - 如何从批处理输出中检查内存是否大于一定数量?