Solved

Batch file to list start menu shortcuts + their targets

Posted on 2007-04-06
15
3,115 Views
Last Modified: 2013-12-28
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
0
Comment
Question by:BillDL
  • 8
  • 7
15 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18868502
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 18868506
Another method that might work...
tree /f /a |find /i ".lnk" >> c:\lnklist.txt
0
 
LVL 38

Author Comment

by:BillDL
ID: 18868532
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 18869425
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
 
LVL 38

Author Comment

by:BillDL
ID: 18869991
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 18870002
:)  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
 
LVL 38

Author Comment

by:BillDL
ID: 18870020
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
Are end users causing IT problems again?

You’ve taken the time to design and update all your end user’s email signatures, only to find out they’re messing up the HTML, changing the font and ruining the imagery. What can you do to prevent this? Find out how you can save your signatures from end users today.

 
LVL 67

Expert Comment

by:sirbounty
ID: 18870035
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
 
LVL 38

Author Comment

by:BillDL
ID: 18870224
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
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18870523
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
 
LVL 38

Author Comment

by:BillDL
ID: 18871542
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 18872148
No need to learn it Bill - just post your needs here! :^)
Glad I could help you.
0
 
LVL 38

Author Comment

by:BillDL
ID: 18872650
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 18872745
:^)
Well, you're welcome to nudge me on my email if you need help getting started.
Best of luck to you!
0
 
LVL 38

Author Comment

by:BillDL
ID: 18873554
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now