0

I created a kind of quick access program in order to rapidly access third party programs/software and folders on my computer. The program works well, but the other day a couple of programs were updated by the software company and this caused exceptions in my program because the paths were changed to the new updated version of their software.

In order to display each program's icon I extract the icon from the third party program's/software's exec file path. But, certain programs contain version or date information "in the path" which is what threw the exceptions (see following list). This also causes exceptions when running the programs because I use the exec path to run each program. So, when the software company updates their software the version or date information in the path changes and throws an exception because the path has changed and my program can no longer find the correct path either to extract the icon or to run the programs?

  • C:\Program Files\Adobe\Adobe Photoshop 2023\Photoshop.exe
  • C:\Program Files (x86)\IObit\Driver Booster\10.0.0\DriverBooster.exe
  • C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
  • C:\Program Files\Paratext 9\Paratext.exe
  • C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe

I am presently thinking of just using the icons in My.Resources as a workaround for the icon extraction issue. But this doesn't resolve the exec paths which I use to run the programs? Does anyone know of a way to update the path information when new program versions are released? I would greatly appreciate some help on this because I've never faced this issue before and honestly don't know where to start to resolve the issue?

My program loads the file paths for each third party software from a text file to a ListBox (i.e. hard-coded). This is part of the problem. Does anyone know how I could code to get the paths for each program in real-time in order to get the actual paths so that they are always updated?

Related Questions on SO

When third party software is updated any software Paths which contain version information (i.e. Version, Year, etc.) change. This prevents icon extraction from hard-coded Paths which have not been updated. As a workaround for this issue I am trying to learn how to extract Paths directly from the Registry, load them at runtime and then extract software icons from updated Paths. Please see my question at the following link which hopefully explains more of what I'm trying to achieve:

Registry-Hierarchy

  • The answer to this case should be helpful to you, you can refer to it. https://stackoverflow.com/questions/14036634/how-to-change-a-program-icon-in-taskbar-vb-net – Hao Yu-MSFT Nov 15 '22 at 06:41
  • Thanks @HaoYu-MSFT, but I'm afraid that doesn't answer my question above. I need to update icons and paths from third party software! – John Michael Wilkinson Nov 15 '22 at 15:09
  • https://www.howtogeek.com/687096/how-to-extract-an-icon-from-a-windows-exe-file/ https://www.codeguru.com/visual-basic/extracting-icons-associated-with-files-in-visual-basic-net/ These two links should help you – Hao Yu-MSFT Nov 21 '22 at 06:21
  • Hey thanks @HaoYu-MSFT! Those links are a great help as I'm interested in studying any alternative methods I can find! However, what I'm currently working on is trying to extract the Paths directly from the Registry at startup in order to minimize problems when extracting icons from paths which the software provider has updated. I'm struggling to find examples of how to achieve this! See: https://stackoverflow.com/questions/74525347/registry-hierarchy-read-different-types-of-values-from-all-levels-of-subkeys – John Michael Wilkinson Nov 21 '22 at 22:13

1 Answers1

0

Open Visual Studio and create a new Visual Basic Windows Forms application. On your form, add the following objects:

Two Buttons One ListView One ImageList Set the following properties for the ListView:

View: SmallIcon SmallImageList: The name of your ImageList Your design should look like Figure 1. [![enter image description here][1]][1] Design

Code:

Public Sub ExtractIcon_1()

      Dim dInfo As New System.IO.DirectoryInfo("c:\")

      Dim lvItem As ListViewItem

      ListView2.BeginUpdate()

      ListView2.Items.Clear()

      Dim CurrFile As System.IO.FileInfo

      For Each CurrFile In dInfo.GetFiles()

         Dim iFileIcon As Icon = SystemIcons.WinLogo

         lvItem = New ListViewItem(CurrFile.Name, 1)

         If Not (ImageList2.Images.ContainsKey _
               (CurrFile.Extension)) Then

            iFileIcon = System.Drawing.Icon.ExtractAssociatedIcon _
               (CurrFile.FullName)

            ImageList2.Images.Add(CurrFile.Extension, iFileIcon)

         End

         lvItem.ImageKey = CurrFile.Extension
         ListView2.Items.Add(

      Next CurrFile

      ListView2.EndUpdate()

   End Sub

Add the following subroutine behind the first button:

Private Sub Button1_Click(sender As Object, e As EventArgs) _
         Handles Button1.Click

      ExtractIcon_1()

   End Sub

https://www.codeguru.com/visual-basic/extracting-icons-associated-with-files-in-visual-basic-net/

  • Since you've collated and posted a new question, you can mark my response as an accepted answer to change its status to answered. It can provide solutions to similar problems for others. Thank you very much! – Hao Yu-MSFT Nov 23 '22 at 07:56
  • Thanks @Hao Yu-MSFT! My question here has been updated for readability! I have already built the example you have given, posted by Hannes DuPreez, but it is missing some bits of the code, e.g. ListView2.Items.Add(??? Please see my other post which maybe explains what I'm trying to achieve: [registry-hierarchy](https://stackoverflow.com/questions/74525347/registry-hierarchy-read-different-types-of-values-from-all-levels-of-subkeys) – John Michael Wilkinson Nov 23 '22 at 15:41
  • I have marked your post as a possible answer, but this example deals with displaying icons (i.e. File Explorer). I am actually attempting to extract updated paths from the Registry and then extract icons directly from the paths. This is a workaround for the issue I mention above of third party software paths which include version information when their software is updated which prevents icon extraction from a hard-coded path! Therefore, I need a way to update the paths when software is updated and if I can learn how to achieve the Registry idea I think it will work! – John Michael Wilkinson Nov 23 '22 at 16:01