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
文件。提取目標將無法使用純批處理。