Get the "Target" of an Shortcut file

2 views (last 30 days)
How can I get the "Target" of an Shortcut file?
i can see it if:
  1. i'm right click on the Shortcut file.
  2. click on "Properties".
  3. under the "Shortcut" title parameter "Target" is listed.
I want to read these parameters using a Matlab command.
I got an answer to my question about how to get the "version" of a file using the commands in the link below, and I think the way should be relatively the same for finding the "target".

Accepted Answer

David Goldfisher
David Goldfisher on 16 Jan 2023
Moved: Voss on 16 Jan 2023
Create a VBS script:
( open a txt file and copy the VBS script into it.
Then rename the file to "GetTargetShortcut.vbs")
' File: GetTargetShortcut.vbs
Set FSO=CreateObject("Scripting.FileSystemObject")
Set Ws = CreateObject("Wscript.Shell")
If Wscript.Arguments.Count > 0 then
sFullFileName = Wscript.Arguments(0)
If FSO.FileExists(sFullFileName) Then
set Lnk = Ws.Createshortcut(sFullFileName)
WScript.echo "LinkTarget: "& Lnk.TargetPath
Else
WScript.Echo "Error: missing file"
End If
Else
WScript.Echo "Error: missing input"
End If
Then call it from Matlab:
file = 'C:\Your\pass\Example.lnk';
[status, result] = system(sprintf('cscript -nologo GetTargetShortcut.vbs "%s"', file))
Output:
result =
'LinkTarget: C:\Example\target.exe
'
Parse this using strsplit and strtrim.
Versions = strsplit(result,': ');
if strcmp(Versions{1},'LinkTarget')
LinkTarget = Versions{2}
else
LinkTarget = [];
end
Output:
LinkTarget =
'C:\Example\target.exe
'

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!