Enumerates all files extensions and what opens them on Windows 10/11 in batch/cmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM °²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²° | |
REM °² Enumerates all files extensions ²° | |
REM °² and what opens them on Windows 10/11 in batch/cmd ²° | |
REM °² twitter: @ollieatnowhere ²° | |
REM °²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²° | |
REM ------------------------------------------------------ | |
REM | |
REM this batch file employs various approaches to | |
REM enumerate what opens what. | |
REM | |
REM ------------------------------------------------------ | |
REM features++ | |
SETLOCAL ENABLEDELAYEDEXPANSION | |
REM --------------------- | |
REM New Windows Approach | |
REM --------------------- | |
REM read the list of file extensions | |
for /f "tokens=1,2 delims==" %%G in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts"') do ( | |
REM extract the last bit of the string i.e. the extension | |
for %%a in ("%%G\.") do ( | |
set "lastPart=%%~nxa" | |
REM find out the users default choice for this extension | |
for /f "tokens=2*" %%I in ('reg query "%%G\UserChoice" 2^>nul ^| findstr ProgId') do ( | |
REM set it to what we think it could be | |
set "exeProg=%%J" | |
REM try the lookup and see what it is (if this fails the above works as a fall back) | |
REM this is for entries from the above which begin with something like ChromeHTML | |
for /f "tokens=2*" %%A in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Classes\%%J\shell\open\command 2^>nul') do ( | |
REM take the bit before the comma | |
for /f "tokens=1 delims=," %%K in ("%%B") do ( | |
set "exeProg=%%K" | |
) | |
) | |
REM try another lookup | |
REM this is for entries from above which begin with AppX | |
for /f "tokens=2*" %%A in ('reg query HKEY_CLASSES_ROOT\%%J\Application 2^>nul ^| findstr AppUserModelID') do ( | |
set "exeProg=%%B" | |
) | |
REM print it out | |
echo %COMPUTERNAME%,!lastPart!,!exeProg! | |
) | |
) | |
) | |
REM --------------------- | |
REM Legacy Windows Approach | |
REM --------------------- | |
REM run assoc and extract the extension and name | |
for /f "tokens=1,2 delims==" %%G in ('assoc') do ( | |
REM find the executable | |
for /f "tokens=1,2 delims==" %%I in ('ftype %%H 2^> nul') do ( | |
REM extract everything before the comma | |
for /f "tokens=1 delims=," %%K in ("%%B") do ( | |
REM print it outd | |
echo %COMPUTERNAME%,%%G,%%J | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment