Changing a files associated icon??

Posted on 2000-05-10
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.
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.


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 200 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
passing parameter in sql procedure 9 70
Excel - Save a copy of work book 13 96
Child Form in front 4 66
how to Classify of email (pdf attachments) 7 57
Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

710 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