|
winprefs 0.4.0
Dump a registry path to a series of 'reg add' commands.
|
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:
-MaxDepth LIMIT or -m LIMIT.REG_UNKNOWN.-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.
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:
-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 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 %.
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.
Delete APPDATA%\prefs-export. Also be sure to delete tasks under tat.sh\WinPrefs in Task Scheduler (taskschd.msc).
Output:
Output:
Output:
Output:
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:
Note the equivalent format names (case-insensitive):
cs, c#ps, ps1, powershellRequirements:
On Windows with Visual Studio installed:
Using the VS developer environment shell is not required but it may help.
After building winprefs.exe will be in build\native\Release\winprefs.exe.
Note: The PowerShell module (C# code) is only buildable with Visual Studio 2022.
After building winprefs.exe will be in build/native/winprefs.exe.
You may need to adjust paths above.
After building winprefs.exe will be in build/native/winprefs.exe.
yarn format: to format the project's files.yarn qa: Perform a QA check.