Skip to content

Instantly share code, notes, and snippets.

@olliencc
Created June 29, 2020 20:28
Show Gist options
  • Save olliencc/aef3e237b9d0455a235ed4c989532f05 to your computer and use it in GitHub Desktop.
Save olliencc/aef3e237b9d0455a235ed4c989532f05 to your computer and use it in GitHub Desktop.
Enumerate via various methods what opens what on Windows 10 using only batch/cmd
@echo off
REM °²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²°
REM °² Enumerates all files extensions ²°
REM °² and what opens them on Windows 10 in batch/cmd ²°
REM °² twitter: @ollieatnccgroup ²°
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