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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center


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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 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…

856 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