Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to follow a windows shortcut to a subdir in cmd.exe?

I have a subdir with a shortcut file in it, let's say it's "shortcut.lnk". and this item is pointing to some other location. when clicking on it in windows explorer the target subdir pops up.

How can I deal with that item using cmd.exe? How can I follow that shortcut using cmd.exe?

I probably don't want to add any third-party software but rather would like to stick and solve this with windows standard tools for portability reasons.

like image 219
alex Avatar asked Aug 27 '15 11:08

alex


People also ask

How do I run a shortcut from the command line?

Run the application using a shortcut to cmd /kRight-click where you want the shortcut created and choose New → Shortcut. Type cmd.exe /k string , where string is the command you want to execute, then click Next. Give the shortcut an appropriate name and click Finish.

How do I add a shortcut to cmd?

Go to the Shortcut tab, then locate the Target field, which lists the exact location of the file within quotation marks. In the Target text box, place the cursor after the last quotation mark, then add a blank space followed by the command line parameters. All command line parameters are preceded with a hyphen (-).


1 Answers

good old VBS seems to be the key for an evidently simple, short and on-board solution:

@echo off
Set Shortcut=%~1

echo set WshShell = WScript.CreateObject("WScript.Shell")>DecodeShortCut.vbs
echo set Lnk = WshShell.CreateShortcut(WScript.Arguments.Unnamed(0))>>DecodeShortCut.vbs
echo wscript.Echo Lnk.TargetPath>>DecodeShortCut.vbs

set vbscript=cscript //nologo DecodeShortCut.vbs
For /f "delims=" %%T in ( ' %vbscript% "%Shortcut%" ' ) do set target=%%T

del DecodeShortCut.vbs

Echo Shortcut %shortcut%
Echo Target   "%target%"
like image 59
alex Avatar answered Oct 15 '22 00:10

alex