Search code examples
vb.netpathwindows-10visual-studio-2019

How do I update Third party software paths and icons in my program?


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


Solution

  • 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/