Windows 10

How to Add a Registry Key in a Batch File

In this tutorial, you’ll learn how to add a registry key in Windows using a batch script. This is particularly useful for system configuration, automation tasks, and deploying settings across multiple machines in enterprise environments.

Batch files provide a way to automate Windows tasks by executing system commands, including manipulating the Windows Registry through the REG command.
 

đź§ľ Syntax
REG ADD [ROOT\]RegKey /v ValueName [/t DataType] [/d Data] [/f]
  • RegKey: Full path of the registry key.
  • /v: Name of the value to be added or modified.
  • /t: Data type (REG_SZ, REG_DWORD, etc.).
  • /d: Data to assign to the registry value.
  • /f: Force overwrite without confirmation.

 
 

📌 Example: Add a Registry Entry via Batch File

The following example adds a new REG_DWORD entry under the UserList registry path, often used to show or hide specific user accounts on the login screen:

@echo off
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList" ^
/v "MyCustomWorkgroupUsername" ^
/t REG_DWORD ^
/d 0 ^
/f

đź’ˇ What this does:

  • Key: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList
  • Value name: MyCustomWorkgroupUsername
  • Type: REG_DWORD (a 32-bit integer value)
  • Data: 0 (This hides the user from the login screen)
  • Switch /f: Forces the update without confirmation prompts.
đź”’ Administrator Privileges Required
⚠️ Important: Editing the Windows registry requires administrator privileges. Ensure your batch file is run with elevated permissions (right-click → Run as administrator).

 

âś… Summary

Using the REG ADD command in a batch script is a powerful method to programmatically modify the Windows Registry. This is commonly used in system hardening, configuration automation, and domain policy scripts.
 

🚀 Boost your productivity with the best AI tools → Try them

 

Leave a Reply

Your email address will not be published. Required fields are marked *