(view source code of shortcut.bat as plain text)
@ECHO OFF
:: Check OS version
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: Keep variables local
SETLOCAL
:: Check command line parameters
IF "%~1"=="" GOTO Syntax
IF NOT EXIST "%~1" GOTO Syntax
:: Check if multiple files were specified
FOR /F %%A IN ('DIR /A-D/B/ON/P/-P "%~1" ^| FIND /C "."') DO SET NUMFILES=%%A
IF "%NUMFILES%"=="1" GOTO ExtCheck
FOR %%A IN ("%~1") DO CALL %0 "%%~A"
GOTO End
:ExtCheck
:: If a single file is specified, the extension should be ".LNK"
IF /I NOT "%~x1"==".LNK" GOTO Syntax
:: Find the shortcut's path
FOR /F "tokens=*" %%A IN ('TYPE "%~1" ^| FIND "\"') DO CALL :Parse "%%~A"
ECHO.
IF "%LINKPATH%"=="" GOTO DispUNC
ECHO Fully qualified path of "%~nx1":
ECHO. %LINKPATH%
ECHO.
:DispUNC
IF "%LINKUNC%"=="" GOTO DispNone
ECHO UNC of "%~nx1":
ECHO. %LINKUNC%
ECHO.
:DispNone
IF NOT "%LINKUNC%"=="" GOTO End
IF NOT "%LINKPATH%"=="" GOTO End
ECHO No path found!
ECHO.
GOTO End
:Parse
SET LINE=%~1
:: Remove leading space introduced by previous line (NT 4 only)
VER | FIND "Windows NT" >NUL
IF NOT ERRORLEVEL 1 IF NOT "%LINE%"=="" SET LINE=%LINE:~1%
:: Skip this line if empty
IF "%LINE%"=="" GOTO:EOF
:: Skip lines beginning with "#"
IF "%LINE:~0,1%"=="#" GOTO:EOF
:: Store UNC of share
IF "%LINE:~0,2%"=="\\" (SET LINKUNC=%LINE%&GOTO:EOF)
:: Store drive
IF "%LINE:~1,2%"==":\" (SET LINKPATH=%LINE%&GOTO:EOF)
:: Skip this line if it starts with "\"
IF "%LINE:~0,1%"=="\" GOTO:EOF
:: Add relative path to UNC and to drive letter
IF NOT "%LINKPATH%"=="" SET LINKPATH=%LINKPATH%%LINE%
IF NOT "%LINKUNC%"=="" SET LINKUNC=%LINKUNC%\%LINE%
GOTO:EOF
:Syntax
ECHO.
ECHO SHORTCUT.BAT, Version 2.10 for Windows NT 4 and later
IF "%OS%"=="Windows_NT" ECHO Shows the fully qualified ^(UNC^) path the specified shortcut file points to.
IF NOT "%OS%"=="Windows_NT" ECHO Shows the fully qualified (UNC) path the specified shortcut file points to.
ECHO.
ECHO Usage: SHORTCUT shortcut_filespec
ECHO.
ECHO Wildcards are allowed in the shortcut filespec.
ECHO Use double quotes if the shortcut filespec contains spaces or ampersands.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
:End
IF "%OS%"=="Windows_NT" ENDLOCAL
page last modified: 2024-04-16; loaded in 0.0087 seconds