0
votes

When I open an exe file the taskbar icon appears correctly, but when I try to open the shortcut of the same exe file, the taskbar icon is different (shows a Default icon). It works fine when combine taskbar button is changed to "Never" in taskbar settings, but if it is in "Always, Hide labels" the above problem is seen.

The Exe Icon:

EXE ICON

The Shortcut Icon:

enter image description here

I am using Microsoft Visual Basic 2010 Express. Application Icon is set programmatically and in Visual Basic Under Application-> Icons - Default option is selected.

The part of my code is given below:

If fs.FileExists(AppPathStr & "\FAQIcon.txt") Then
  Me.Icon = New Icon(AppPathStr & "\" & "filecontent.ico")
Else
  Me.Icon = New Icon(AppPathStr & "\" & "Project1.ico")
End If

I have found a similar problem in the Link that says that the exe file and the shortcut of the same exe file should not be pointing at the same location.

Instead I need to point the shortcut exe to a launcher application that shells out to the main application, but I don't want to have a launcher application.

Does anyone know the solution for this problem ?

1
Also try using just double quotes for everything in your example; not double double quotes. i.e. AppPathStr & "\FAQIcon.txt" and AppPathStr & "\Project1.ico". - J. Scott Elblein

1 Answers

0
votes

What happens if you switch to using the icons as resources instead of reading them from disk?

i.e. Right-click on your project | properties | resources, add the 2 icons as images, then:

If fs.FileExists(AppPathStr & "\FAQIcon.txt") Then
     Me.Icon = My.Resources.filecontent
   Else
     Me.Icon = My.Resources.Project1
End If

Side Note: You could also add the Faqicon.txt file to your resources and extract it as needed as well, then you won't have to test for it existing on disk; you just extract it as needed and set the icon to match, i.e.:

' Extract the FAQIcon.txt resource
Dim b() As Byte = My.Resources.FAQIcon

' Write it to the folder
File.WriteAllBytes(AppPathStr & "\FAQIcon.txt", b)

or don't even bother extracting it to a file if you don't need to, for example, just load it into a text box:

FAQIcon.Text = My.Resources.FAQIcon