Link to home
Start Free TrialLog in
Avatar of BillDL
BillDLFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of sirbounty
sirbounty
Flag of United States of America image

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...
Another method that might work...
tree /f /a |find /i ".lnk" >> c:\lnklist.txt
Avatar of BillDL

ASKER

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
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..
Avatar of BillDL

ASKER

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:

https://www.experts-exchange.com/questions/22402045/Merging-two-DOS-commands-to-make-one-big-batch-file.html?anchorAnswerId=18576155#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
:)  Looks good.
If that doesn't work - I'd imagine I could come up with a vbscript for this...if that's an option...
Avatar of BillDL

ASKER

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.
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.
Avatar of BillDL

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BillDL

ASKER

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
No need to learn it Bill - just post your needs here! :^)
Glad I could help you.
Avatar of BillDL

ASKER

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.
:^)
Well, you're welcome to nudge me on my email if you need help getting started.
Best of luck to you!
Avatar of BillDL

ASKER

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.