WinPrefs is a developer tool designed to export registry paths into script and code formats such as reg commands, PowerShell, C, or C#. It allows users to dump a specific registry path into executable scripts or formatted code snippets for use in development workflows.
Key Features:
Converts registry entries into reg add commands, compatible with batch files.
Outputs values as C# or C binary data structures for integration into native applications.
Supports PowerShell scripting by automatically adjusting command syntax.
Filters registry keys and values based on configurable wildcards to exclude unwanted data.
Includes a native executable that works across Windows versions, including XP and newer.
Audience & Benefit:
Ideal for developers and system administrators who need to automate registry backups or integrate registry settings into software. WinPrefs simplifies the creation of registry-based scripts and reduces manual effort in generating code from registry exports. It can be installed via winget, making it easy to incorporate into development environments.
macOS users: please see macprefs for an equivalent tool.
This package dumps a registry path to equivalent reg commands. It contains two commands.
Save-Preferences creates a batch script composed of reg commands for copying into a script.
Write-RegCommands is effectively the same but requires a path argument and only writes to standard
output.
By default both commands default to a maximum depth of 20. Save-Preferences defaults to path
HKCU:.
Note that by default only HKCU: and HKLM: are mounted in PowerShell. Others need to be mounted
and must be under the appropriate name such as HKU for HKEY_USERS.
Keys/values are skipped under these conditions:
Depth limit (default: 20); this can be changed by passing -MaxDepth LIMIT or -m LIMIT.
Key that cannot be read for any reason such as permissions.
Value contains newlines.
Value has type REG_UNKNOWN.
Value is filtered. Pass -S or --no-settings to disable filters.
An example of an always skipped key under normal circumstances is HKLM\SECURITY, even if this is
run as administrator.
Be sure to set up Git with your user name and email (git config --global user.email, etc) before
using the commit feature.
Values can be filtered by adding wildcard strings to HKCU\Software\Tatsh\WinPrefs\Filters
(HKLM will be used for users in the administrator group). Example to ignore all values that have
Cache in the path:
On first launch, a default set of filters will be added. If you do not want these, delete the values
under the key but do not delete the key HKLM\Software\Tatsh\WinPrefs\Filters.
WARNING: If you save an entire tree such as HKLM: to a file and attempt to run said script, you
probably will break your OS. The output of this tool is meant for getting a single command at a
time, testing it, and then using it in an appropriate script. The author will not be held
responsible for any damages.
Installation
Install-Module -Name WinPrefs
Usage
Save-Preferences
# or the alias:
prefs-export
Save-Preferences generates an exec-reg.bat (default name) file and saves to
${env:APPDATA}\prefs-export by default. This can be changed by passing -OutputDirectory DIR
(or -o DIR). The file name can be changed by passing -OutputFile FILE (or -f FILE).
The format can be changed with the -Format argument. Accepted format strings:
It accepts switch -Commit/-c to initialise and commit to a Git repository in the output
directory. It also accepts a -DeployKey PATH parameter and will push if this is specified. Any
other Git management such as the branch name, etc must be managed in the output directory manually.
Write-RegCommands HKCU:
# or the alias
path2reg HKCU:
Write-RegCommands prints out equivalent reg commands to reproduce the keys/values at the given
path. reg command output is escaped for Batch file only. No variables will be present in the
output. If you want to use a reg command in PowerShell you need to replace %% with %.
Automated Usage
You can create a scheduled task that will run every 12 hours to backup a registry path.
Register-SavePreferencesScheduledTask (winprefs-install-job) can be called multiple times with
different -Path arguments. Like Save-Preferences it can automatically commit to a repository and
push.
Calling Register-SavePreferencesScheduledTask multiple times with the same -Path argument will
not break anything. If a task with the same name already exists, it must be unregistered before its
replacement can be made.
Any task can be uninstalled with Unregister-SavePreferencesScheduledTask (winprefs-uninstall-job)
with the same -Path argument.
Uninstallation
Delete %APPDATA%\prefs-export. Also be sure to delete tasks under tat.sh\WinPrefs in Task
Scheduler (taskschd.msc).
Examples
Save HKEY_LOCAL_MACHINE\Control Panel with a depth of 1
The PowerShell module makes use of the native code with DllImport to get a significant speed
increase in making registry queries and performing I/O. A native binary winprefs.exe can also be
built that can be used without needing PowerShell installed and it should work with XP and newer. If
built as a a 32-bit binary, the native binary should be compatible with Windows 2000 and newer. It
even works with Wine.
The path name should be of the form: HIVE\Key\SubKey. Do not leave a trailing \.
Usage is similar to the PowerShell version:
Usage: winprefs.exe [OPTION...] [REG_PATH]
If a path to a value name is specified, the output directory argument is ignored and the line is
printed to standard output.
Options:
-F, --format=FORMAT Format to output. Options: c, cs, c#, ps, ps1, powershell, reg. Default: reg.
-K, --deploy-key Deploy key for committing.
-c, --commit Commit changes.
-d, --debug Enable debug logging.
-f, --output-file Output filename.
-m, --max-depth=INT Set maximum depth.
-o, --output-dir Output directory.
-h, --help Display this help and exit.
Note the equivalent format names (case-insensitive):