Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


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:

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

722 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