Solved

Changing a files associated icon??

Posted on 2000-05-10
11
368 Views
Last Modified: 2012-05-05
how do i change the icon associated with a file?
0
Comment
Question by:smiffe
  • 3
  • 2
  • 2
  • +3
11 Comments
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
The below site help will help you to get started.

http://www.thescarms.com/VBasic/ShellLnk.htm
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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)

http://vbaccelerator.com/codelib/inireg/registry.htm
0
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
The below site help will help you to get started.

http://www.thescarms.com/VBasic/ShellLnk.htm
0
 
LVL 1

Expert Comment

by:philchang
Comment Utility
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.


0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
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.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 14

Expert Comment

by:wsh2
Comment Utility
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", _
      "c:\MyPathname\MyIcon.ico)

   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

RegError:
End Function

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


0
 

Author Comment

by:smiffe
Comment Utility
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.
0
 

Author Comment

by:smiffe
Comment Utility
kDivad please post that url
0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
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!
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 200 total points
Comment Utility
<<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.
0
 

Author Comment

by:smiffe
Comment Utility
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, _
        "$(Programs)"
      CreateIcon = True
    Case 1 'StartMenu/Programs
      fCreateShellLink "..\Programs", IconTitle, ProgramPath, "", -1, _
        "$(Programs)"
      CreateIcon = True
    Case 2 'StartMenu
      fCreateShellLink "..", IconTitle, ProgramPath, "", -1, _
        "$(Programs)"
      CreateIcon = True
    Case 3 'StartMenu/Programs/Startup will auto run at startup
      fCreateShellLink "..\Programs\StartUp", IconTitle, ProgramPath, "", -1, _
        "$(Programs)"
      CreateIcon = True
    Case Else 'invalid call Get out
      CreateIcon = False
  End Select
  Exit Function
ErrorHandler:
  CreateIcon = False
End Function

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now