Go Premium for a chance to win a PS4. Enter to Win


Changing a files associated icon??

Posted on 2000-05-10
Medium Priority
Last Modified: 2012-05-05
how do i change the icon associated with a file?
Question by:smiffe
  • 3
  • 2
  • 2
  • +3

Expert Comment

ID: 2797498
The below site help will help you to get started.

LVL 28

Expert Comment

ID: 2797512
you will need to access the registry to change the key marked "Deafult Icon" for the file
check out this nice sample that wraps up all the registry functionality into a class module  (get key values, save key values, change key values)


Expert Comment

ID: 2797513
The below site help will help you to get started.

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 2797938
An easy way to get change an icon associated with a file type:

1. Create an icon, attach it to your project (Project|Properties).

2. Create a File Association using Visual Studio Installer.  The file association will make any file type use your project's icon.

If you don't have it, VS Installer is free from Microsoft.  It replaces PDW and is much cooler (installs look like Office 2000).  Download it at: http://msdn.microsoft.com/vstudio/downloads/vsi/default.asp

Click on the FAQ to learn about what other neat things VSI can do.


Expert Comment

ID: 2798792
Another easy way is a component I wrote. It'll let you change the icon with one line of code and optionally flush the icon cache so that Explorer will show the updated icon. If you are interested, let me know and I'll post a URL.
LVL 14

Expert Comment

ID: 2798952
This code does a programatic file association:

'  Instructions:
'  1.  Add a new Standard.Exe Project.
'  2.  Set a reference (Vb Menu -> Projects -> References) to "Windows Scripting Runtime".
'  3.  Copy/Paste the folowing into the code window.
'  4.  Change the File Association and MyApp MyPath parameters to whatever you want.
'  5.  Press F5 to Run

<----- Code Begin ----->

Option Explicit

Private Sub Form_Load()
   MsgBox (xAddFileAssociation( _
      "xxx", _
      "MyApp.Document", _
      "My Application Document", _
      "c:\MyPath\Myapp.exe %1", _
      "c:\MyPath\MyIcon.ico) _

End Sub

Private Function xAddFileAssociation _
(ByVal strExtName As String, _
ByVal strAppName As String, _
ByVal strAppDesc As String, _
ByVal strAppCommand As String, _
ByVal strAppIcon As String) _
As Boolean

'  SynTax:
'  booReturn = xFileAssociation(strExtName, strAppName, strAppDesc, strAppCommand, strAppIcon)

'  Parameters:
'  booReturn: Returns true if add is successful.
'  strExtName: File extension characters. (Eg. For Text.TXT this would be TXT)
'  strAppName: Registry Key (usually the application name) that association data will be stored under. Note: No Spaces.
'  strAppDesc: File Association description as it will appear in Windows Explorer.
'  strAppCommand: The program executable command line when the file is double clicked on. Explorer will pass the file name clicked on as Parameter 1. (Eg. "c:\MyPathname\Myapp.exe %1")
'  strAppIcon: File Icon.
(Eg. "c:\MyPathname\Myapp.exe,3") -or- (Eg. "c:\MyPathname\Myapp.ico)

'  Example Usage:
'  booReturn = xFileAssociation( _
      "xxx", _
      "MyApp.Document", _
      "My Application Document", _
      "c:\MyPathname\Myapp.exe %1", _

   Dim oWSH As New IWshShell_Class
   Dim strWork As String
   On Error GoTo RegError
   oWSH.RegWrite "HKCR\." & strExtName & "\", strAppName
   oWSH.RegWrite "HKCR\" & strAppName & "\", strAppDesc
   oWSH.RegWrite "HKCR\" & strAppName & "\shell\open\command\", strAppCommand
   oWSH.RegWrite "HKCR\" & strAppName & "\defaulticon\", strAppIcon

   On Error GoTo 0
   xAddFileAssociation = True

End Function

<----- Code End ----->


Author Comment

ID: 2799072
i don't want to change the icon associated with a file type. i dont want all exe files to show my icon i just want to be able to change what shows on the users desktop for a single file such as Test.exe i think maybe i didn't word the question very clear.

Author Comment

ID: 2799076
kDivad please post that url

Expert Comment

ID: 2799098
Umm...I would, but it would "change the icon associated with a file type" which is exactly what you said you didn't want.

You want to change the icon that is displayed by your exe, correct? It's a simple process really. You need to make the icon of any form in your app match the one you want. On the menu, select "Project" - "ProjectName Properties". On the form that comes up, select the "Make" tab. In the frame named "Application", select the form you assigned the icon to from the combobox. When you compile, this new icon will be the one that the user sees.

If you want to change the icon for an app you don't have the source for, you are out of luck. Similarly, I don't think Windows supports using different files for most non-executable files.

Hope This Helps!
LVL 28

Accepted Solution

AzraSound earned 600 total points
ID: 2799189
<<If you want to change the icon for an app you don't have the source for, you are out of luck>>

thats what i thought was being asked, however if that were the case i think it could be done, by tampering with the registry...you will notice the DefaultIcon key of files specify the filename and then the icon number embedded in that file...e.g.,
"C:\Program Files\ActiveSkin\SkinBuilder.exe,0"

i assume you could change this to any other files icon that you wanted or any other embedded icon number within that file.

Author Comment

ID: 2799248
Thankyou all for your help the reason i wanted to do this is because i wrote a function to
create shell links on the users computer and i wanted to be able to control what icon showed
up.  I now know this is very hard if not impossible so i will forget it.  Well anyway here
my function maybe someone can get some use out of it.

Private Declare Function fCreateShellLink Lib "vb6stkit.dll" _
  (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, _
  ByVal lpstrLinkPath As String, _
  ByVal lpstrLinkArgs As String, ByVal fPrivate As Integer, _
  ByVal sParent As String) As Long

Public Function CreateIcon(IconTitle As String, ProgramPath As String, _
  Optional PutWhere As Integer = 0) As Boolean

  On Error Goto ErrorHandler
  Select Case PutWhere
    Case 0 'desktop
      fCreateShellLink "..\..\Desktop", IconTitle, ProgramPath, "", -1, _
      CreateIcon = True
    Case 1 'StartMenu/Programs
      fCreateShellLink "..\Programs", IconTitle, ProgramPath, "", -1, _
      CreateIcon = True
    Case 2 'StartMenu
      fCreateShellLink "..", IconTitle, ProgramPath, "", -1, _
      CreateIcon = True
    Case 3 'StartMenu/Programs/Startup will auto run at startup
      fCreateShellLink "..\Programs\StartUp", IconTitle, ProgramPath, "", -1, _
      CreateIcon = True
    Case Else 'invalid call Get out
      CreateIcon = False
  End Select
  Exit Function
  CreateIcon = False
End Function

bye the way this will only work in vb6 or if
you include the file vb6stkit.dll

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

971 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