File associations are registered under
HKEY_LOCAL_MACHINE\SOFTWARE\Classes for all users of a machine and under
HKEY_CURRENT_USER\Software\Classes for the current user. Windows combines these two registry keys with current user file associations taking precendence over the local machine file assocations to
HKEY_CLASSES_ROOT.
Let us assume a user associated via the graphical user interface of Windows the file extension
.nfo with UltraEdit which could be done also in a command prompt window by running the following two command lines:
assoc .nfo=
UltraEdit
ftype UltraEdit=^"^%ProgramFiles^%\IDM Computer Solutions\UltraEdit\uedit64.exe^" "%1"
The
.nfo file association is stored in the Windows registry as follows:
Code: Select all
[HKEY_CLASSES_ROOT\.nfo]
@="UltraEdit"
[HKEY_CLASSES_ROOT\UltraEdit\Shell\Open\Command]
@=hex(2):22,00,25,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,46,00,69,00,6c,\
00,65,00,73,00,25,00,5c,00,49,00,44,00,4d,00,20,00,43,00,6f,00,6d,00,70,00,\
75,00,74,00,65,00,72,00,20,00,53,00,6f,00,6c,00,75,00,74,00,69,00,6f,00,6e,\
00,73,00,5c,00,55,00,6c,00,74,00,72,00,61,00,45,00,64,00,69,00,74,00,5c,00,\
75,00,65,00,64,00,69,00,74,00,36,00,34,00,2e,00,65,00,78,00,65,00,22,00,20,\
00,22,00,25,00,31,00,22,00,00,00
The file association is registered either in registry hive of current user or in registry hive of local machine depending on the user used own account with write permissions only for
HKEY_CURRENT_USER\Software\Classes or a local administrator account with using an elevated execution environment (run as administrator) for having write access also to
HKEY_LOCAL_MACHINE\SOFTWARE\Classes.
Most users create a file association via the graphical user interface of Windows. There are several possibilities which I do not describe here as they differ from Windows version to Windows version although they all result in the same actions in Windows registry.
How to change the icon associated with a file type depends on how the user associated a file extension. Let us assume the user does not have the permissions to run
Registry Editor of Windows as administrator and wants to change the icon for a file type.
The user has to open a command prompt window and run the command
assoc with the file extension which is in this example:
.nfo
assoc .nfo
The Windows command
assoc outputs the associated file type registration which is the default string value of
HKEY_CLASSES_ROOT\.nfo.
.nfo=
UltraEdit
The user has to run next the command
ftype with the string output after the equal sign to get displayed the registered shell command for opening files with file extension
.nfo which is here
UltraEdit.
ftype UltraEdit
The output for this example is:
UltraEdit="%ProgramFiles%\IDM Computer Solutions\UltraEdit\uedit64.exe" "%1"
All the hexadecimal bytes in the UTF-16 Little Endian encoded registry export above become now readable in this output.
hex(2): in the above export is the type of a registry value of type
REG_EXPAND_SZ because of the string value contains the environment variable reference
%ProgramFiles% which Windows has first to
expand before getting real string. The shell open command could be registered also with a string value of type
REG_SZ if the string does not contain an environment variable reference. Most shell open commands for file types use
REG_SZ as string value type.
The Windows command
ftype cannot be used to change the icon associated with a file type. It does not even register which file contains the icon for the file type.
A user should execute therefore next first the following command line with the file type string
UltraEdit for this example.
reg QUERY "
HKCU\Software\Classes\
UltraEdit\Shell\Open\Command" /ve
The user knows the file type registration was done only for the current user if there is the same string output as before on execution of
ftype. Otherwise there is output the error message:
ERROR: The system was unable to find the specified registry key or value.
The user should run in that case the following command in the command prompt window:
reg QUERY "
HKLM\Software\Classes\
UltraEdit\Shell\Open\Command" /ve
Now the user should see the output as before with
ftype and knows that the file type is registered for all users of local machine. In this case the user should close the current command prompt window and open a new one with
Run as administrator and use the next commands with
HKLM instead of
HKCU from within elevated command prompt window.
Let us assume next the file
ue-icon.ico offered for download by
hugov exported with
Resource Hacker (really good free tool often used by me) from UltraEdit executable of version 2022.2 containing this icon file in its resources is stored by the user in the directory
%ProgramFiles%\IDM Computer Solutions\UltraEdit (using elevated permissions of a local administrator). Then the user has to run next in the command prompt window either
reg ADD "
HKCU\Software\Classes\
UltraEdit\DefaultIcon" /f /ve /t
REG_EXPAND_SZ /d "\"^%ProgramFiles^%\IDM Computer Solutions\UltraEdit\ue-icon.ico\""
or
reg ADD "
HKCU\Software\Classes\
UltraEdit\DefaultIcon" /f /ve /t
REG_SZ /d "\"%ProgramFiles%\IDM Computer Solutions\UltraEdit\ue-icon.ico\""
The first command adds the default icon string as expandable string containing the environment variable reference
%ProgramFiles% while the second command adds the default icon string as standard string with
%ProgramFiles% expanded already by the
Windows Command Processor before running
%SystemRoot%\System32\reg.exe.
The fully qualified file name of the icon file can be whatever is wanted by the user. This is just an example.
It is necessary to restart Windows to see the changed icons for the file types in
Windows File Explorer as the command
reg does not send an appropriate message to all running instances of
explorer.exe including the
Explorer instance running as Windows shell with Windows desktop, Windows Start button and Windows taskbar as visually visible graphic elements to inform them to update the icon cache.
There are of course also other methods to change the default icon for a file type like running
Registry Editor as administrator on having permissions to do at all and edit the default icon registry string value with
Registry Editor or using graphical interface. But all the other methods depend on version of Windows and which permissions the user has which is the reason why a described the change of the default icon using Windows commands which every user on every Windows can execute.