Is there a way I can force all specific file types to open in notepad if I set a user as non administrator?
This is for a shul’s oitzer hachochma to block video and music playback
Is there a way I can force all specific file types to open in notepad if I set a user as non administrator?
This is for a shul’s oitzer hachochma to block video and music playback
Copilot made this script
will it work if anyone knows windows
# ---------------------------------------------------------
# Force ALL file types (except .exe and .pdf) to open in Notepad
# Windows 11 Home compatible
# ---------------------------------------------------------
Write-Host "Enumerating all registered file extensions..." -ForegroundColor Cyan
# Get all extensions registered under HKLM\Software\Classes
$allExts = Get-ChildItem "HKLM:\Software\Classes" |
Where-Object { $_.Name -match "\\\." } |
Select-Object -ExpandProperty PSChildName
# Exclusions
$exclude = @(".exe", ".pdf")
# Filter extensions
$targetExts = $allExts | Where-Object { $exclude -notcontains $_.ToLower() }
Write-Host "Found $($targetExts.Count) extensions to force to Notepad."
# ---------------------------------------------------------
# 1. Set HKLM machine-wide associations
# ---------------------------------------------------------
foreach ($ext in $targetExts) {
$progId = "txtfile"
reg add "HKLM\Software\Classes\$ext" /ve /d $progId /f | Out-Null
reg add "HKLM\Software\Classes\$progId\shell\open\command" /ve /d "`"%SystemRoot%\system32\notepad.exe`" `"%1`"" /f | Out-Null
Write-Host "Associated $ext with Notepad"
}
# ---------------------------------------------------------
# 2. Remove UserChoice overrides
# ---------------------------------------------------------
Write-Host "`nRemoving UserChoice overrides..." -ForegroundColor Cyan
foreach ($ext in $targetExts) {
$ucPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$ext\UserChoice"
if (Test-Path $ucPath) {
Remove-Item $ucPath -Recurse -Force
Write-Host "Removed UserChoice for $ext"
}
}
# ---------------------------------------------------------
# 3. Lock registry keys to prevent override
# ---------------------------------------------------------
Write-Host "`nLocking registry keys..." -ForegroundColor Cyan
foreach ($ext in $targetExts) {
$keyPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$ext"
if (-not (Test-Path $keyPath)) {
New-Item $keyPath -Force | Out-Null
}
$acl = Get-Acl $keyPath
$rule = New-Object System.Security.AccessControl.RegistryAccessRule("Users","SetValue,CreateSubKey,Delete","Deny")
$acl.AddAccessRule($rule)
Set-Acl $keyPath $acl
Write-Host "Locked $ext"
}
Write-Host "`nAll done! All file types except .exe and .pdf now open in Notepad." -ForegroundColor Green
and block the open with menu via
# Block Windows 11 modern "Open with" menu
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" -Force | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" `
-Name "{09799AFB-AD67-11d1-ABCD-00C04FC30936}" -Value "" -PropertyType String -Force | Out-Null