1.

Solve : How to read target of .lnk file with command line?

Answer» strings.exe can be used to remove unwanted characters.
Code: [Select]C:\Documents and Settings\Administrator\Desktop>strings myshortcut.lnk

Strings v2.41
Copyright (C) 1999-2009 Mark Russinovich
Sysinternals - www.sysinternals.com

+00
#C:\
&:<s1
Program Files
PROGRA~1
&:<s
Novativa Streamster
NOVATI~1
&:=s
Streamster.exe
STREAM~1.EXE
C:\Program Files\Novativa Streamster\Streamster.exe
O*{
O*{
OK So I've got:
Code: [Select]@echo off
REM example
echo 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
echo 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%">>target.txt And the output:
Code: [Select]C:\VB>ShortcutTarget.bat "C:/Documents and Settings/All Users/Desktop/Adobe Acro
bat 6.0 Professional.lnk"
Set Shortcut="C:/Documents and Settings/All Users/Desktop/Adobe Acrobat 6.0 Prof
essional.lnk"
set vbscript=cscript //nologo DecodeShortCut.vbs
C:\VB\DecodeShortCut.vbs(2, 1) WshShell.CreateShortcut: The shortcut PATHNAME mu
st end with .lnk or .url.

Shortcut
It seems like it would work if I could GET rid of the quotes around the path as it seems to want the last characters to be .lnk
So can I substring "C:/Documents and Settings/All Users/Desktop/Adobe Acrobat 6.0 Prof
essional.lnk"
to read C:/Documents and Settings/All Users/Desktop/Adobe Acrobat 6.0 Prof
essional.lnk
in my batch file? I need the quotes in the dos box since the path contains spaces?Quote from: nubia on April 06, 2009, 06:51:14 AM
OK So I've got:
Code: [Select]@echo off
REM example
echo Set Shortcut=%1
...

The line with REM example can be removed; it was just to show where an example was in the original batch.

There should not be an echo at the start of the next line! It should just be set Shortcut=[something]

Quote
I need the quotes in the dos box since the path contains spaces?

Yes, that is correct, and the solution is to PASS the shortcut name with quotes from the command line like this

Code: [Select]ShortcutTarget.bat "C:/Documents and Settings/All Users/Desktop/Adobe Acrobat 6.0 Professional.lnk"
But in the batch strip the quotes off using the tilde ("~") variable modifier: so use %~1 instead of %1 as you see below.



@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%


I want to thank all of you who have helped me in this.
Dias especially. You have not only solved the problem you have taught me a lot, for which I am grateful.
This is a great site and I HOPE some day to be able to help others.
But it seems that I am way BEHIND every one and would like to learn more about Dos programming and vb script too.
I, from necessity, have jumped into the middle of this and think it would be a good idea to read a primer on the subjects. (Dos programming and vb script).
My best to all!


Discussion

No Comment Found