Batch file to list start menu shortcuts + their targets

Hi Experts
I've been trying to thin out and streamline a problem Win98 (1st edition) system using a remote connection by VNC.  It's hard going, because the problem PC is on a standard dialup modem connection.  I'm on broadband, but the screen refresh time lag makes it really difficult navigating the start menu, and frequently causes me to click the wrong shortcut and launch app's that freeze the system.

There's a lot of redundant start menu folders and shortcuts, and I was hoping to try and get a listing of the shortcuts and the targets they point to by running a batch file rather than having to check out the property pages of each shortcut one at a time.

I can get the target of a given shortcut into a text file using the command:
type "file name.lnk" | find /i "c:\" > linknames.txt
but I can't figure a way that would traverse through the start menu listing the *.LNK files and then acting on each one to give a list something like this:

C:\Windows\Start Menu\Programs\Prog1 Folder\Shortcut1.lnk
C:\Program Files\Program1\Target1.exe
C:\Windows\Start Menu\Programs\Prog2 Folder\Shortcut2.lnk
C:\Program Files\Program2\Target2.exe
etc.

I'm aware of the CHKLNKS.EXE program in the Win98 Resource Kit, but I would rather get a listing and verify at my end while offline that the start menu folders and shortcuts were no longer needed before then deleting them using a batch file created from the listing.

Any ideas?  Maybe using the FOR command or something?
A small freeware utility program that could create such a listing would be a good alternative.

Thanks
Bill
LVL 39
BillDLAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sirbountyCommented:
Hey Bill - I don't know for sure if the 98 version of for lists /r as a parameter?
If so, try this:

for /r c:\ %a in (*.lnk) do echo %a
(from a command prompt).
I'm thinking that maybe it doesn't - but worth a shot...
0
sirbountyCommented:
Another method that might work...
tree /f /a |find /i ".lnk" >> c:\lnklist.txt
0
BillDLAuthor Commented:
Thanks for the suggestions, sirbounty.

I would have to use the old DOS 6.22 TREE program, use Setver to set add it to the version table, and load setver at startup.  No great problem, it lists using 8.3 names, but I can use them in a batch file just the same.

Without trying either option though, it doesn't look at first glance as though they will list both the *.lnk file with a fully qualified path AND the target it points to.

I'll test them out though.
Bill
0
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

sirbountyCommented:
Nope you're right..I read that and skipped right over that requirement...sorry about that.
Well, as I'm not convinced myself that either will work for you - I'll wait for your response - if it works, it shouldn't be too much trouble to add that bit in - I was more interested in if the /r was supported..
0
BillDLAuthor Commented:
Thanks sirbounty.  I went and forgot to test that when I was connected to the user's PC by VNC the last time.  Definitely tonight :-)

I suggested a long-winded method to gather different information (but in a similarly sorted manner) in another E-E question, and I can try that if there isn't an alternative batch only method:

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/Q_22402045.html#a18576155

Transposed to this scenario, it may work by adding your FOR command suggestion with the /R switch if it works in Win98:

@echo off
:: Create list of qualified paths to Start Menu Links
cd \
cd "C:\Windows\Start Menu\Programs"
dir /on /b /s "*.lnk" > %TEMP%\TmpList.txt
:: Add line numbers to all lines in new temp file
type %TEMP%\TmpList.txt | find /i /n "C:" > %TEMP%\tmp_01.txt
:: Walk through start menu and sequentially
:: get details of the target for each link in a
:: numbered list below the directory list in same file.
:: /R assumes current directory if not qualified
cd \
cd windows\startm~1
for /r %%a in (*.lnk) do type %%a | find /i /n "C:" >> %TEMP%\tmp_01.txt
:: Sort the list so all the 1's, 2's, etc are grouped
cd \
cd %TEMP%
sort /+2 tmp_01.txt > LinkList.txt
:: Cleanup
del %TEMP%\TmpList.txt > nul
del %TEMP%\tmp_01.txt > nul
exit

Use Wordpad Find and replace to add commas, save as a *.csv file, load in Excel, and delete column 1 which contains the numbers.

I'll try this and let you know, unless you can see any glaring errors in my FOR command line.  I don't use the FOR command too often you see :-)

Bill
0
sirbountyCommented:
:)  Looks good.
If that doesn't work - I'd imagine I could come up with a vbscript for this...if that's an option...
0
BillDLAuthor Commented:
Hey, that was quick.  Are you never off E-E?
Yeah, anything's an option.  As I say, the connection is so slow that it's really aggravating manually deleting redundant start menu folders from the viewing interface.  Getting the details of the shortcuts will also give me a good idea of the leftover folders from uninstallations that are cluttering up the root and program files directories, and I can use the deltree command on them from another batch file.
Thanks.
0
sirbountyCommented:
How could I be 'off' EE?  Haha
Actually I'm headed to the store, but will work on a test script for you when I get back.
Hopefully one of these will work.  With the vbs, I can output the file in any format you want...even drop it into excel, if you'd like...
So, would you like a csv/excel file for this?
Let me know the output you're looking for.
0
BillDLAuthor Commented:
Either format would do, sirbounty, but don't spend too long creating a VBScript though.  No sense in you ruining a Saturday drinking that beer you're heading off to the store to buy.

Actually, I discovered something I hadn't been aware of.  The Win98 Dead Link Checker (chklnks.exe) displays checkboxes of dead links found, but by name only.  I hadn't realised it shows a properties dialog immediately on a right-click, and these show greyed-out File, Location, Resolves To, and Error Code fields.  I've messed with the resources of the *.exe (Resource hacker) and made the fields accessible to copy the paths from.  Still not automated, but usable at a push.
0
sirbountyCommented:
Nope - no beer this weekend. Haha

Here's the output from the following script.  I'm not sure if it'll work under 98, or if it'll have a prereq of the scripting host runtime....(been too long for me and 98, although I still have a few clients that run it).

C:\Documents and Settings\Administrator\Start Menu\Programs\Remote Assistance.lnk,C:\WINDOWS\system32\rcimlby.exe
C:\Documents and Settings\Administrator\Start Menu\Programs\Windows Media Player.lnk,C:\Program Files\Windows Media Player\wmplayer.exe
C:\Documents and Settings\Administrator\Start Menu\Programs\Accessories\Command Prompt.lnk,C:\WINDOWS\system32\cmd.exe

Note the above is 'full path to the shortcut", a comma, and the target for the shortcut....hope I didn't misunderstand the requirements.

Here's the script - it's recursive...in my test it was against C:\Documents and Settings - presumably yours would be changed to C:\Windows ?
Let me know. :^)

'LocateSC.vbs

'' /// Setup environment declarations and object references ///
Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell:Set objShell = CreateObject("Wscript.Shell")
Dim objFolder:Set objFolder = objFSO.GetFolder("C:\Documents and Settings\")
Dim objOutput:Set objOutput = objFSO.CreateTextFile("C:\Shortcuts.txt")

' /// Run the main routine, ProcessFolder, a recursive search through the files/folders found in the objFolder reference ///
  ProcessFolder (objFolder)

' /// Close file and destroy object references, finalizing the script ///
objOutput.Close
Set objOutput=Nothing
Set objFolder=Nothing
Set objShell=Nothing
Set objFSO=Nothing
wscript.quit

' /// Main routine to scan current folder and recursively call against sub folders ///
Sub ProcessFolder(fld)
  Set subFld = objFSO.GetFolder(fld) ' Set object reference against current folder
  ProcessFile (subFld) 'Call Processfile routine against current folder
  For Each fld In subFld.SubFolders 'loop through all subfolders, recalling the same routine
    ProcessFolder (fld)
  Next
End Sub

' /// Routine to process all container files within the passed folder reference
Sub ProcessFile(fld)
  Set objFld = objFSO.GetFolder(fld) 'create object reference to the current folder
  For Each file In objFld.Files 'loop through all files found
  If objFSO.GetExtensionName(file) = "lnk" Then 'if the extension is 'lnk', it's a shortcut - only proceed if this returns TRUE
    Set objFile = objShell.CreateShortcut(file) 'create a shell reference to the file
    objOutput.WriteLine file & "," & objFile.TargetPath  'Write the file path and target path values to the output file
    Set objFile = Nothing 'destory object reference
  End If
Next
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BillDLAuthor Commented:
Thank you for that one sirbounty.
The VBS Script ran perfectly with changes to reference the Win98 Start Menu.  So much easier than messing with batch files.  I keep saying to myself that I should learn some VB, but never seem to get around to it.  That should have taught me a lesson.
Bill
0
sirbountyCommented:
No need to learn it Bill - just post your needs here! :^)
Glad I could help you.
0
BillDLAuthor Commented:
Actally, sirbounty, you commented your script well enough that I could probably use it as a basis for a few other routines without having to ask.  It's a lot easier to follow than the 16-bit C Programming I had to cover in its basics as part of a college course, in that the functions use plain English.

There's no good excuse for me not having learned useful programming  languages, because I have the legit install CD's and reference CD's for for Visual Studio 6 Enterprise, Visual Studio Express 2005, Visual J++ 6.0, Borland C++ 5 Builder, Delphi 6, and several others.  I know some people in third- world countries would give their left arm for them, and I've just been plain lazy.

I suppose part of the difficulty is knowing where to start and not having a structured learning path to follow as you would have if learning through a college course.  Until then I'll ask and know I'll get great answers like this.
0
sirbountyCommented:
:^)
Well, you're welcome to nudge me on my email if you need help getting started.
Best of luck to you!
0
BillDLAuthor Commented:
Thank you immensely for that offer, sirbounty.  There's obviously a fine line between what should properly be asked here and what can be asked off-site, so I would be conscious of that, but may well "nudge" you at some point for some initial advice.

In fact, watch for a question fairly soon in the VB TA.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.