找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 117|回复: 6

[注册表类] 如何禁止修改注册表的某个项

[复制链接]
发表于 9 小时前 | 显示全部楼层 |阅读模式
已知“HKCR\.xxx”项为空,且无任何子项,我想锁定它,让任何程序都不能写入。用regset.ini修改后没用,如图。
未标题-1.jpg
发表于 7 小时前 | 显示全部楼层
脚本和工具很难实现的,手动把权限和审核全部去除才可以。。。。。
发表于 6 小时前 | 显示全部楼层
实现禁止的操作均有对应的 '逆操作' 化解,只是操作难度的差别。
要看你防御哪个层次的人了,对擅长此道的老手,化解都不是事,尤其如今的 ai 可谓如虎添翼...
 楼主| 发表于 6 小时前 | 显示全部楼层
aloha20200628 发表于 2026-8-17 11:47
实现禁止的操作均有对应的 '逆操作' 化解,只是操作难度的差别。
要看你防御哪个层次的人了,对擅长此道的 ...

不考虑逆操作,不能写入就行
发表于 5 小时前 | 显示全部楼层
你使用“管理员”权限修建了马奇诺防线。
程序也能拿到“管理员”权限(甚至更高权限),它当然能把你修的马奇诺防线给拆掉啦:)
发表于 5 小时前 | 显示全部楼层
AI:
RegClassLock.bat
  1. @echo off
  2. setlocal EnableExtensions

  3. :: Auto elevate
  4. fltmc >nul 2>&1
  5. if errorlevel 1 (
  6.     powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
  7.     exit /b
  8. )

  9. cls
  10. echo ==========================================
  11. echo        HKCR Extension Lock Tool
  12. echo ==========================================
  13. echo.

  14. set /p "EXT=Input extension, for example .xxx: "

  15. if "%EXT%"=="" exit /b

  16. :: Automatically add "." if omitted
  17. if not "%EXT:~0,1%"=="." set "EXT=.%EXT%"

  18. echo.
  19. echo Target:
  20. echo     HKCR\%EXT%
  21. echo.
  22. echo [1] Lock
  23. echo [2] Unlock
  24. echo [0] Exit
  25. echo.

  26. choice /c 120 /n /m "Select: "

  27. if errorlevel 3 exit /b
  28. if errorlevel 2 goto unlock
  29. if errorlevel 1 goto lock


  30. :lock
  31. cls
  32. echo Locking HKCR\%EXT% ...
  33. echo.

  34. :: HKCR is merged from these two locations
  35. reg add "HKCU\Software\Classes\%EXT%" /f >nul 2>&1
  36. reg add "HKLM\Software\Classes\%EXT%" /f >nul 2>&1

  37. powershell -NoProfile -Command "$ErrorActionPreference='Stop';try{$deny=[System.Security.AccessControl.RegistryRights]([int][System.Security.AccessControl.RegistryRights]::SetValue -bor [int][System.Security.AccessControl.RegistryRights]::CreateSubKey -bor [int][System.Security.AccessControl.RegistryRights]::Delete);$open=[System.Security.AccessControl.RegistryRights]([int][System.Security.AccessControl.RegistryRights]::ReadPermissions -bor [int][System.Security.AccessControl.RegistryRights]::ChangePermissions);$sid=New-Object System.Security.Principal.SecurityIdentifier('S-1-1-0');$rule=New-Object System.Security.AccessControl.RegistryAccessRule($sid,$deny,[System.Security.AccessControl.InheritanceFlags]::ContainerInherit,[System.Security.AccessControl.PropagationFlags]::None,[System.Security.AccessControl.AccessControlType]::Deny);foreach($base in @([Microsoft.Win32.Registry]::CurrentUser,[Microsoft.Win32.Registry]::LocalMachine)){$k=$base.OpenSubKey('Software\Classes\%EXT%',[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,$open);$acl=$k.GetAccessControl();$acl.RemoveAccessRuleSpecific($rule)|Out-Null;$acl.AddAccessRule($rule);$k.SetAccessControl($acl);$k.Close()};exit 0}catch{Write-Host $_;exit 1}"

  38. if errorlevel 1 (
  39.     echo.
  40.     echo [ERROR] Lock failed.
  41. ) else (
  42.     echo.
  43.     echo [OK] HKCR\%EXT% is locked.
  44.     echo.
  45.     echo Blocked:
  46.     echo   - Set or modify values
  47.     echo   - Create subkeys
  48.     echo   - Delete the key
  49. )

  50. echo.
  51. pause
  52. exit /b


  53. :unlock
  54. cls
  55. echo Unlocking HKCR\%EXT% ...
  56. echo.

  57. powershell -NoProfile -Command "$ErrorActionPreference='Stop';try{$deny=[System.Security.AccessControl.RegistryRights]([int][System.Security.AccessControl.RegistryRights]::SetValue -bor [int][System.Security.AccessControl.RegistryRights]::CreateSubKey -bor [int][System.Security.AccessControl.RegistryRights]::Delete);$open=[System.Security.AccessControl.RegistryRights]([int][System.Security.AccessControl.RegistryRights]::ReadPermissions -bor [int][System.Security.AccessControl.RegistryRights]::ChangePermissions);$sid=New-Object System.Security.Principal.SecurityIdentifier('S-1-1-0');$rule=New-Object System.Security.AccessControl.RegistryAccessRule($sid,$deny,[System.Security.AccessControl.InheritanceFlags]::ContainerInherit,[System.Security.AccessControl.PropagationFlags]::None,[System.Security.AccessControl.AccessControlType]::Deny);foreach($base in @([Microsoft.Win32.Registry]::CurrentUser,[Microsoft.Win32.Registry]::LocalMachine)){$k=$base.OpenSubKey('Software\Classes\%EXT%',[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,$open);if($k){$acl=$k.GetAccessControl();$acl.RemoveAccessRuleSpecific($rule)|Out-Null;$k.SetAccessControl($acl);$k.Close()}};exit 0}catch{Write-Host $_;exit 1}"

  58. if errorlevel 1 (
  59.     echo.
  60.     echo [ERROR] Unlock failed.
  61. ) else (
  62.     echo.
  63.     echo [OK] HKCR\%EXT% is unlocked.
  64. )

  65. echo.
  66. pause
  67. exit /b
复制代码


初步测试通过。
发表于 5 小时前 | 显示全部楼层

测试用的脚本,一并附上,右键管理员执行

AI:

  1. @echo off
  2. setlocal
  3. set "EXT=.zzacltest95250"

  4. net session >nul 2>&1
  5. if errorlevel 1 (
  6.     echo [ERROR] 请右键以管理员身份运行
  7.     pause
  8.     exit /b
  9. )

  10. echo === 创建测试项 ===
  11. reg delete "HKCU\Software\Classes\%EXT%" /f >nul 2>&1
  12. reg delete "HKLM\Software\Classes\%EXT%" /f >nul 2>&1
  13. reg add "HKCU\Software\Classes\%EXT%" /f >nul
  14. reg add "HKLM\Software\Classes\%EXT%" /f >nul

  15. echo.
  16. echo === 加锁 ===

  17. powershell -NoProfile -Command "$ErrorActionPreference='Stop';$deny=[System.Security.AccessControl.RegistryRights]([int][System.Security.AccessControl.RegistryRights]::SetValue -bor [int][System.Security.AccessControl.RegistryRights]::CreateSubKey -bor [int][System.Security.AccessControl.RegistryRights]::Delete);$open=[System.Security.AccessControl.RegistryRights]([int][System.Security.AccessControl.RegistryRights]::ReadPermissions -bor [int][System.Security.AccessControl.RegistryRights]::ChangePermissions);$sid=New-Object System.Security.Principal.SecurityIdentifier('S-1-1-0');$rule=New-Object System.Security.AccessControl.RegistryAccessRule($sid,$deny,[System.Security.AccessControl.InheritanceFlags]::ContainerInherit,[System.Security.AccessControl.PropagationFlags]::None,[System.Security.AccessControl.AccessControlType]::Deny);foreach($base in @([Microsoft.Win32.Registry]::CurrentUser,[Microsoft.Win32.Registry]::LocalMachine)){$k=$base.OpenSubKey('Software\Classes\%EXT%',[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,$open);$acl=$k.GetAccessControl();$acl.AddAccessRule($rule);$k.SetAccessControl($acl);$k.Close()};exit 0"

  18. if errorlevel 1 (
  19.     echo [ERROR] 加锁失败
  20.     goto cleanup
  21. )

  22. echo [OK] 加锁成功

  23. echo.
  24. echo === 测试 ===

  25. reg add "HKCR\%EXT%" /v test /d 123 /f >nul 2>&1
  26. if errorlevel 1 (echo [PASS] HKCR 写值被阻止) else (echo [FAIL] HKCR 写值成功)

  27. reg add "HKCR\%EXT%\abc" /f >nul 2>&1
  28. if errorlevel 1 (echo [PASS] HKCR 创建子项被阻止) else (echo [FAIL] HKCR 创建子项成功)

  29. reg add "HKCU\Software\Classes\%EXT%" /v test /d 123 /f >nul 2>&1
  30. if errorlevel 1 (echo [PASS] HKCU 写值被阻止) else (echo [FAIL] HKCU 写值成功)

  31. reg add "HKLM\Software\Classes\%EXT%" /v test /d 123 /f >nul 2>&1
  32. if errorlevel 1 (echo [PASS] HKLM 写值被阻止) else (echo [FAIL] HKLM 写值成功)

  33. reg delete "HKCU\Software\Classes\%EXT%" /f >nul 2>&1
  34. if errorlevel 1 (echo [PASS] HKCU 删除被阻止) else (echo [FAIL] HKCU 删除成功)

  35. reg delete "HKLM\Software\Classes\%EXT%" /f >nul 2>&1
  36. if errorlevel 1 (echo [PASS] HKLM 删除被阻止) else (echo [FAIL] HKLM 删除成功)

  37. :cleanup
  38. echo.
  39. echo === 恢复 ===

  40. powershell -NoProfile -Command "$ErrorActionPreference='SilentlyContinue';$deny=[System.Security.AccessControl.RegistryRights]([int][System.Security.AccessControl.RegistryRights]::SetValue -bor [int][System.Security.AccessControl.RegistryRights]::CreateSubKey -bor [int][System.Security.AccessControl.RegistryRights]::Delete);$open=[System.Security.AccessControl.RegistryRights]([int][System.Security.AccessControl.RegistryRights]::ReadPermissions -bor [int][System.Security.AccessControl.RegistryRights]::ChangePermissions);$sid=New-Object System.Security.Principal.SecurityIdentifier('S-1-1-0');$rule=New-Object System.Security.AccessControl.RegistryAccessRule($sid,$deny,[System.Security.AccessControl.InheritanceFlags]::ContainerInherit,[System.Security.AccessControl.PropagationFlags]::None,[System.Security.AccessControl.AccessControlType]::Deny);foreach($base in @([Microsoft.Win32.Registry]::CurrentUser,[Microsoft.Win32.Registry]::LocalMachine)){$k=$base.OpenSubKey('Software\Classes\%EXT%',[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,$open);if($k){$acl=$k.GetAccessControl();$acl.RemoveAccessRuleSpecific($rule);$k.SetAccessControl($acl);$k.Close()}}"

  41. reg delete "HKCU\Software\Classes\%EXT%" /f >nul 2>&1
  42. reg delete "HKLM\Software\Classes\%EXT%" /f >nul 2>&1

  43. echo 测试项已清理
  44. pause
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-8-17 18:34

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表