Windows (7|10) Registry Mods

Negotiating the labyrinth.

Keys affecting File Type Association (FTA) and other useful mods

Change a filetype's icon, reported type, and handler(s), and/or add a (custom) app to File Explorer's context menu. The relevant registry keys, and two CLI-based methods for modifying them, are detailed herein. One method involves exporting, modifying, and then adding back .reg files. The other method is entirely programmatic. Both allow for scripting to batch process any list of such mods.

Lots of mystery, paranoia, and misinformation surround the Windows registry. Having worked with it quite a bit over the decades, experience indicates that any target key(s) should first be exported and archived, unaltered, as can be the entire registry. Keys can then be restored simply and reliably, unless the damage is too extensive. Again from experience, just about the only way to truly screw things up beyond the target key is to programmatically insert a malformed key or entry. That is, to inject improper syntax. Even then, it takes a very unfortunate mix of such syntax to harm the registry irreparably, or otherwise even affect it beyond the target key. The registry is not fragile.

FTA entries

HKCR\.{TYPE}

HKCR\{TYPE}file

Again, this subkey name, {TYPE}file, is just an example. Such keys may be auto-generated by some related app, per install or other process; or created by us. As mentioned in the section on the primary file-type key, HKCR\.{TYPE}, the standard naming convention for this FTA key, used by applications for their FTAs, is HKCR\{APP}.{TYPE} or HKCR\{APP}{TYPE}. And absent any such app, the naming convention is HKCR\{TYPE}file or HKCR\{TYPE}_auto_file. All such keys are equivalents; they're for these FTA settings. Just make sure the primary key points to the one containing the desired mods, whatever its name. It's okay for several such keys to exist for a given file-type, even though only one is used.

HKCR\Applications\{APPNAME}

HKCU\SOFTWARE\...\Explorer\FileExts\.{TYPE}

UserChoice is where FTA and icon settings are hijacked per app. The subkey is overwritten per subsequent user-select (UserChoice) actions, "Open with"->"Always use ...", unlike setting(s) at the HKCR\{TYPE}file key. Comparing mods at the two hives, HKCR vs. HKCU, while the immediate effects from any user-select actions are the same, the big difference is that HKCR settings recover (FTA & icon) upon user-select back to whatever handlers were programmed therein. Whereas any mods here (HKCU\...\UserChoice) are gone, having been overwritten. This is the cause of much user unhappiness.

HKCR\Directory

Programmatically Add/Modify/Delete Registry Keys

regedit /s FILE.reg method.

Delete

regedit /s FILE.reg

At times when the reg delete KEYpath /f method fails per DENIED: ..., this method succeeds.

Add

regedit /s FILE.reg

reg add|delete KEYpath method.

Delete

reg delete ROOTKEY\SubKey /f 

    ROOTKEY  [ HKLM | HKCU | HKCR | HKU | HKCC ]

    /va        delete all values under this key.

    /f         Forces the deletion without prompt.

E.g., delete the key and all subkeys thereunder:

reg delete HKCR\foofile /f   

Add

reg add ROOTKEY\SubKey ...

    ROOTKEY  [ HKLM | HKCU | HKCR | HKU | HKCC ]

    /v       The value name, under the selected Key, to add.

    /ve      adds an empty value name (Default) for the key

    /t       RegKey data types (defaults to REG_SZ)
             [ REG_SZ  | REG_MULTI_SZ | REG_EXPAND_SZ |
             REG_DWORD | REG_QWORD    | REG_BINARY    | REG_NONE ]

    /d       The data to assign to the registry ValueName being added.

    /f       Force overwriting the existing registry entry without prompt.

Examples

Add default (custom) icon for filetype foo:

reg add HKCR\foofile\DefaultIcon /ve /d "C:\ICONS\foo.ico"  

Creates a default (REG_SZ) data-type value at an "empty value name", @=..., entry:

[HKEY_CLASSES_ROOT\foofile\DefaultIcon]  
@="C:\\ICONS\\foo.ico"  

Add the NeverShowExt value (flag) for filetype foo:

reg add HKCR\foofile /v "NeverShowExt"

Creates a value name having an empty string value of default (REG_SZ) data type:

[HKEY_CLASSES_ROOT\foofile]  
"NeverShowExt"=""  

Add foo filetype and its template file, New.foo, to File Explorer's New menu:

reg add HKCR\.foo\ShellNew /v "FileName" /d "C:\ICONS\ShellNew\New.foo"
reg add HKCR\.foo\ShellNew /v "Nullfile"

Creates:

[HKEY_CLASSES_ROOT\.foo\ShellNew]
"FileName"="C:\\ICONS\\ShellNew\\New.foo"
"Nullfile"=""

FTA; associate filetype foo with its edit handler (app):

reg add HKCR\foofile\shell\edit\command /ve /t REG_EXPAND_SZ   
/d "\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"^%1\""  

Creates a REG_EXPAND_SZ data type:

[HKEY_CLASSES_ROOT\foofile\shell\edit\command]  
@=hex(2):22,00,43,00,3a,00,5c,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,\  
00,20,00,46,00,69,00,6c,00,65,00,73,00,5c,00,5c,00,4d,00,69,00,63,00,72,00,\  
6f,00,73,00,6f,00,66,00,74,00,20,00,56,00,53,00,20,00,43,00,6f,00,64,00,65,\  
00,5c,00,5c,00,43,00,6f,00,64,00,65,00,2e,00,65,00,78,00,65,00,22,00,20,00,\  
22,00,25,00,31,00,22,00,00,00  

FTA, same as above, using the default data-type:

reg add HKCR\foofile\shell\edit\command /ve   
/d "\"C:\Program Files\Microsoft VS Code\Code.exe\" \"^%1\"" /f  

Creates:

[HKEY_CLASSES_ROOT\foofile\shell\edit\command]  
@="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"%1\""  

 

FTA.Add.cmd (example script)

@echo off
:: -------------------------------------------------------
::  REG ADD :: FTA for filetype %1
::  
::  - Requires app path (hardcoded here) 
:: -------------------------------------------------------

::set _prog=C:\Program Files\7-Zip\7zFM.exe
::set _icons=C:\ICONS\archs
set _prog=C:\Program Files\Microsoft VS Code\Code.exe
set _icons=C:\ICONS
set _ext=%~1
if not exist "%_prog%" ( echo. & echo   ABORTed :: App does NOT EXIST & echo. & pause & goto :eof )
if not exist "%_icons%" ( echo. & echo   ABORTed :: '%_icons%' folder does NOT EXIST & echo. & pause & goto :eof )
if "%_ext%" == "" ( echo. & echo   ABORTed :: filetype name [extension name] REQUIREd & echo. & pause & goto :eof )
echo. & echo   REG ADD :: Set FTA and such for filetype '%_ext%' & echo. & pause & echo. 

:: ==  HKCR  ==

echo DEL+ADD @ HKCR\.%_ext% 
reg delete HKCR\.%_ext% /f
reg add HKCR\.%_ext% /ve /d "%_ext%file"

echo DEL+ADD @ HKCR\%_ext%file
reg delete HKCR\%_ext%file /f
reg add HKCR\%_ext%file /ve /d "%_ext%"
reg add HKCR\%_ext%file /v "NeverShowExt"
reg add HKCR\%_ext%file\DefaultIcon /ve /d "%_icons%\%_ext%.ico,0"

:: no app yet associated with filetype, so "Open with ..." (Always) selection allows
:: user-selected app to PERMANENTLY steal/replace the icon. So need to specify app here:
echo DEL+ADD @ HKCR\%_ext%file\shell
reg delete HKCR\%_ext%file\shell /f
reg add HKCR\%_ext%file\shell\open\command /ve /d "\"%_prog%\" \"^%%1\"" 

:: ==  HKCU  ==

echo DEL @ HKCU\...\FileExts\.%_ext% 
:: Windows overwrites this key per user's "Open with ..." (Always) selection
:: That's how icon setting is hijacked per app, 
:: so UNSET (DELETE) ONLY. Can set it, but don't have to (usually).
:: Deletion DENIED if associated with , e.g., Notepad.exe ; if so, use reg key method, [-HKEY....], instead.
::reg delete HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%_ext% /f
>  "%TEMP%\HKCU.%_ext%.reg" echo Windows Registry Editor Version 5.00
>> "%TEMP%\HKCU.%_ext%.reg" echo. 
>> "%TEMP%\HKCU.%_ext%.reg" echo [-HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%_ext%]
regedit /s "%TEMP%\HKCU.%_ext%.reg"

echo ADD empties @ HKCU\...\FileExts\.%_ext%\... +OpenWithList +OpenWithProgids +UserChoice
:: Add back empty keys
>  "%TEMP%\HKCU.%_ext%.reg" echo Windows Registry Editor Version 5.00
>> "%TEMP%\HKCU.%_ext%.reg" echo. 
>> "%TEMP%\HKCU.%_ext%.reg" echo [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%_ext%]
>> "%TEMP%\HKCU.%_ext%.reg" echo. 
>> "%TEMP%\HKCU.%_ext%.reg" echo [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%_ext%\OpenWithList]
>> "%TEMP%\HKCU.%_ext%.reg" echo. 
>> "%TEMP%\HKCU.%_ext%.reg" echo [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%_ext%\OpenWithProgids]
>> "%TEMP%\HKCU.%_ext%.reg" echo. 
>> "%TEMP%\HKCU.%_ext%.reg" echo [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%_ext%\UserChoice]
regedit /s "%TEMP%\HKCU.%_ext%.reg"

:: 'HKCU\...\OpenWithList' not needed
::echo ADD @ HKCU\...\FileExts\.%_ext%\OpenWithList 
::reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%_ext%\OpenWithList /ve /t REG_SZ 

:: 'HKCU\...\OpenWithProgids' not needed
::echo ADD @ HKCU\...\FileExts\.%_ext%\OpenWithProgids 
::reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%_ext%\OpenWithProgids /v "%_ext%file" /t REG_NONE

:: 'HKCU\...\UserChoice' not needed (usually)
:: Windows overwrites this key per user's "Open with ..." (Always) selection
::echo ADD @ HKCU\...\FileExts\.%_ext%\UserChoice 
::reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%_ext%\UserChoice /v "ProgId" /d "%_ext%file" 


echo. & echo   DONE & echo. & pause
goto :eof
*********