Introduction
Batch scripts can read, write, modify, and delete Windows registry keys using
the built-in reg command. This tutorial shows you the safe and
practical ways to edit the registry without corrupting the system.
1. Reading Registry Values
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"
HKCU = Current User HKLM = Local Machine (system-wide)
2. Adding a Registry Key
reg add "HKCU\Software\CodeTweakrs" /v UserMode /t REG_SZ /d "Pro" /f
Explanation:
- /v → value name
- /t → type (REG_SZ, REG_DWORD, etc.)
- /d → data
- /f → force overwrite
3. Editing an Existing Value
reg add "HKLM\Software\Policies\System" /v DisableCMD /t REG_DWORD /d 0 /f
This changes the value if it already exists.
4. Deleting a Value
reg delete "HKCU\Software\CodeTweakrs" /v UserMode /f
5. Deleting an Entire Key
reg delete "HKCU\Software\CodeTweakrs" /f
6. Example: Disable Windows Lock Screen
reg add "HKLM\Software\Policies\Microsoft\Windows\Personalization" ^
/v NoLockScreen /t REG_DWORD /d 1 /f
7. Example: Add Startup Program
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" ^
/v CTTool /t REG_SZ /d "C:\Tools\CTTool.exe" /f
8. Tips & Warnings
- Always back up keys before editing.
- HKLM modifications require Administrator privileges.
- Incorrect registry edits can break Windows settings.
- Use
reg exportto back up.
reg export "HKCU\Software" backup.reg
Summary
The reg command is extremely powerful. With it you can automate
system tweaks, software configuration, startup control, and advanced system
management directly from Batch scripts.