In My Computer and Windows Explorer, the Tools / Folder Options / File Types dialog provides a graphical method
of changing file associations. In tip 3674, I
described how to prevent users
from changing any file association using the GUI.
To prevent a user from changing an association, run:
EditFlags .ext, where .ext is the file extension.
EditFlags.bat contains:
@echo off
setlocal
if {%1}"" goto syntax
regedit /a %temp%\oldEF.reg "HKEY_CLASSES_ROOT\%ftype%"
@echo REGEDIT4>%temp%\NewEF.reg
@echo.>>%temp%\NewEF.reg
@echo [HKEY_CLASSES_ROOT\%ftype%]>>%temp%\NewEF.reg
set sw=Y
set ef=N
set ef1=0
set ef2=1
set ef3=0
set ef4=0
set ef5=0
set ef6=0
set ef7=0
set ef8=0
for /f "Skip=3 Tokens=1* Delims==" %%a in ('type %temp%\oldEF.reg') do set vn=%%a&set string=%%b&call :parse
if "%ef%" EQU "Y" @echo "EditFlags"=->>%temp%\NewEF.reg
goto hide%ef8%
:hide0
set ef8=1
goto out
:hide1
goto out
:hide2
set ef8=3
goto out
:hide3
goto out
:hide4
set ef8=5
goto out
:hide5
goto out
:hide6
set ef8=7
goto out
:hide7
goto out
:hide8
set ef8=9
goto out
:hide9
goto out
:hideA
set ef8=B
goto out
:hideB
goto out
:hideC
set ef8=D
goto out
:hideD
goto out
:hideE
set ef8=F
goto out
:hideF
:out
@echo "EditFlags"=dword:%ef1%%ef2%%ef3%%ef4%%ef5%%ef6%%ef7%%ef8%>>%temp%\NewEF.reg
regedit /s %temp%\NewEF.reg
del /q %temp%\NewEF.reg
del /q %temp%\oldEF.reg
goto :EOF
:parse
if "%sw%" EQU "N" goto :EOF
set vn=%vn:"=%
if "%vn:~0,1%" EQU "[" set sw=N&goto :EOF
if /i not "%vn%" EQU "EditFlags" goto :EOF
set ef=Y
if /i "%string:~0,6%" EQU "dword:" goto efdw
if /i "%string:~0,4%" EQU "hex:" goto efhx
goto :EOF
:efdw
set ef1=%string:~6,1%
set ef2=%string:~7,1%
set ef3=%string:~8,1%
set ef4=%string:~9,1%
set ef5=%string:~10,1%
set ef6=%string:~11,1%
set ef7=%string:~12,1%
set ef8=%string:~13,1%
goto :EOF
:efhx
set ef7=%string:~4,1%
set ef8=%string:~5,1%
set ef5=%string:~7,1%
set ef6=%string:~8,1%
set ef3=%string:~10,1%
set ef4=%string:~11,1%
set ef1=%string:~13,1%
set ef2=%string:~14,1%