【问题标题】:Extract Path from shortcut link - windows batch从快捷方式链接中提取路径 - Windows 批处理
【发布时间】:2017-04-04 14:42:18
【问题描述】:

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

【问题讨论】:

    标签: batch-file


    【解决方案1】:

    您可以通过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!
    

    【讨论】:

      【解决方案2】:

      你可以试试shortcutjs.bat

      call shortcutjs.bat "some.lnk"^| find /i "target:"
      

      与 vbscript 一样,它也使用 windows 脚本主机,但使用其他内置语言 - jscript ,但包装在 .bat 文件中。纯批处理无法提取目标。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-08
        • 1970-01-01
        • 2020-10-04
        • 1970-01-01
        • 2010-10-11
        • 2018-09-22
        • 2017-08-01
        • 1970-01-01
        相关资源
        最近更新 更多