virt-win-reg(1)

okay bestie, welcome to virt-win-reg(1) ๐Ÿ’– this is the Virtualization Support page, and weโ€™re gonna make the Windows Registry feel less like a haunted basement and more like a group chat you can actually follow. no cap.

๐ŸŒธ NAME ๐ŸŒธ

virt-win-reg โ€” export and merge Windows Registry entries from a Windows guest. thatโ€™s the whole gig ๐Ÿ’…

โœจ SYNOPSIS โœจ

hereโ€™s the shape of it, fr fr:

virt-win-reg domname 'HKLM\Path\To\Subkey'

virt-win-reg domname 'HKLM\Path\To\Subkey' name

virt-win-reg domname 'HKLM\Path\To\Subkey' @

virt-win-reg --merge domname [input.reg ...]

virt-win-reg [--options] disk.img ... # instead of domname

๐Ÿšจ WARNING ๐Ÿšจ

You must not use virt-win-reg with the --merge option on live virtual machines. If you do this, you will get irreversible disk corruption in the VM. virt-win-reg tries to stop you from doing this, but doesnโ€™t catch all cases. not me showing up to a live VM with merge mode like itโ€™s a cute little craft project ๐Ÿ˜ญ it is not.

Modifying the Windows Registry is an inherently risky operation. The format is deliberately obscure and undocumented, and Registry changes can leave the system unbootable. Therefore when using the --merge option, make sure you have a reliable backup first. do not skip the backup, periodt.

๐Ÿซถ DESCRIPTION ๐Ÿซถ

This program can export and merge Windows Registry entries from a Windows guest.

The first parameter is the libvirt guest name or the raw disk image of a Windows guest.

If --merge is not specified, then the chosen registry key is displayed/exported (recursively). For example:

$ virt-win-reg Windows7 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft'

You can also display single values from within registry keys, for example:

$ cvkey='HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
$ virt-win-reg Windows7 $cvkey ProductName
Windows 7 Enterprise

With --merge, you can merge a textual regedit file into the Windows Registry:

$ virt-win-reg --merge Windows7 changes.reg

๐Ÿ“ NOTE ๐Ÿ“

This program is only meant for simple access to the registry. If you want to do complicated things with the registry, we suggest you download the Registry hive files from the guest using libguestfs(3) or guestfish(1) and access them locally, eg. using hivex(3), hivexsh(1) or hivexregedit(1). like, this is the โ€œsimple access onlyโ€ disclaimer and it ate ๐Ÿ’…

๐Ÿ’– OPTIONS ๐Ÿ’–

hereโ€™s every flag, no skips, no vibes-based guessing:

  • --help โ€” Display brief help. short and sweet.
  • --version โ€” Display version number and exit. iconic behavior.
  • --debug โ€” Enable debugging messages. for when you need the tea โ˜•
  • -c URI, --connect URI โ€” If using libvirt, connect to the given URI. If omitted, then we connect to the default libvirt hypervisor.

If you specify guest block devices directly, then libvirt is not used at all. direct mode, no middleman.

  • --format raw โ€” Specify the format of disk images given on the command line. If this is omitted then the format is autodetected from the content of the disk image.

If disk images are requested from libvirt, then this program asks libvirt for this information. In this case, the value of the format parameter is ignored.

If working with untrusted raw-format guest disk images, you should ensure the format is always specified. this is a real safety vibe check, bestie.
  • --merge โ€” In merge mode, this merges a textual regedit file into the Windows Registry of the virtual machine. If this flag is not given then virt-win-reg displays or exports Registry entries instead.
Note that --merge is unsafe to use on live virtual machines, and will result in disk corruption. However exporting (without this flag) is always safe. so like... export? yes. live merge? absolutely not.
  • --encoding UTF-16LE|ASCII โ€” When merging (only), you may need to specify the encoding for strings to be used in the hive file. This is explained in detail in "ENCODING STRINGS" in Win::Hivex::Regedit(3).

The default is to use UTF-16LE, which should work with recent versions of Windows.

  • --unsafe-printable-strings โ€” When exporting (only), assume strings are UTF-16LE and print them as strings instead of hex sequences. Remove the final zero codepoint from strings if present.

This is unsafe and does not preserve the fidelity of strings in the original Registry for various reasons:

  • Assumes the original encoding is UTF-16LE. ASCII strings and strings in other encodings will be corrupted by this transformation.
  • Assumes that everything which has type 1 or 2 is really a string and that everything else is not a string, but the type field in real Registries is not reliable.
  • Loses information about whether a zero codepoint followed the string in the Registry or not.

This all happens because the Registry itself contains no information about how strings are encoded (see "ENCODING STRINGS" in Win::Hivex::Regedit(3)).

You should only use this option for quick hacking and debugging of the Registry contents, and never use it if the output is going to be passed into another program or stored in another Registry. itโ€™s giving โ€œtemporary chaos onlyโ€ ๐Ÿ’€

๐ŸŒˆ SUPPORTED SYSTEMS ๐ŸŒˆ

The program currently supports Windows NT-derived guests starting with Windows XP through to at least Windows 8.

The following Registry keys are supported:

  • HKEY_LOCAL_MACHINE\SAM
  • HKEY_LOCAL_MACHINE\SECURITY
  • HKEY_LOCAL_MACHINE\SOFTWARE
  • HKEY_LOCAL_MACHINE\SYSTEM
  • HKEY_USERS\.DEFAULT
  • HKEY_USERS\SID โ€” where SID is a Windows User SID (eg. S-1-5-18).
  • HKEY_USERS\username โ€” where username is a local user name (this is a libguestfs extension).

You can use HKLM as a shorthand for HKEY_LOCAL_MACHINE, and HKU for HKEY_USERS.

The literal keys HKEY_USERS\$SID and HKEY_CURRENT_USER are not supported (there is no "current user"). no โ€œcurrent userโ€ main character energy here, sorry ๐Ÿซ 

๐ŸชŸ WINDOWS 8 ๐ŸชŸ

Windows 8 "fast startup" can prevent virt-win-reg from being able to edit the Registry. See "WINDOWS HIBERNATION AND WINDOWS 8 FAST STARTUP" in guestfs(3).

๐Ÿงš ENCODING ๐Ÿงš

virt-win-reg expects that regedit files have already been re-encoded in the local encoding. Usually on Linux hosts, this means UTF-8 with Unix-style line endings. Since Windows regedit files are often in UTF-16LE with Windows-style line endings, you may need to re-encode the whole file before or after processing.

To re-encode a file from Windows format to Linux (before processing it with the --merge option), you would do something like this:

iconv -f utf-16le -t utf-8 < win.reg | dos2unix > linux.reg

To go in the opposite direction, after exporting and before sending the file to a Windows user, do something like this:

unix2dos linux.reg | iconv -f utf-8 -t utf-16le > win.reg

For more information about encoding, see Win::Hivex::Regedit(3).

If you are unsure about the current encoding, use the file(1) command. Recent versions of Windows regedit.exe produce a UTF-16LE file with Windows-style (CRLF) line endings, like this:

$ file software.reg
software.reg: Little-endian UTF-16 Unicode text, with very long lines,
with CRLF line terminators

This file would need conversion before you could --merge it. lowkey a whole little encoding side quest, but you got this ๐Ÿ’ช

๐ŸŒ€ CurrentControlSet etc. ๐ŸŒ€

Registry keys like CurrentControlSet donโ€™t really exist in the Windows Registry at the level of the hive file, and therefore you cannot modify these.

CurrentControlSet is usually an alias for ControlSet001. In some circumstances it might refer to another control set. The way to find out is to look at the HKLM\SYSTEM\Select key:

# virt-win-reg WindowsGuest 'HKLM\SYSTEM\Select'
[HKEY_LOCAL_MACHINE\SYSTEM\Select]
"Current"=dword:00000001
"Default"=dword:00000001
"Failed"=dword:00000000
"LastKnownGood"=dword:00000002

Current is the one which Windows will choose when it boots.

Similarly, other Current... keys in the path may need to be replaced.

๐ŸŽ€ DELETING REGISTRY KEYS AND VALUES ๐ŸŽ€

To delete a whole registry key, use the syntax:

[-HKEY_LOCAL_MACHINE\Foo]

To delete a single value within a key, use the syntax:

[HKEY_LOCAL_MACHINE\Foo]
"Value"=-

๐ŸŒธ WINDOWS TIPS ๐ŸŒธ

โš ๏ธ Heads up bestie, some of these tips literally modify the guest disk image. The guest must be shut off โ€” otherwise you get disk corruption and it's giving disaster. ๐Ÿ’€

๐Ÿ’ฅ ENABLING CRASH DUMPS ๐Ÿ’ฅ

First up, prep a regedit file with the registry change:

cat > test.reg <<'EOF'
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\CrashControl]
"CrashDumpEnabled"=dword:00000002
EOF

(Quick note: this assumes "CurrentControlSet" is "ControlSet001". Peep the "CurrentControlSet etc." section above if that's not your vibe. ๐Ÿซถ)

Then update the registry, slay:

virt-win-reg --merge WindowsGuest test.reg

"dword:00000002" enables kernel memory dumps. "dword:00000001" enables complete memory dumps. (See https://learn.microsoft.com/en-us/troubleshoot/windows-server/performance/memory-dump-file-options#registry-values-for-startup-and-recovery โ€” iykyk โœจ)

The memory dump gets written to either "%SystemRoot%\Memory.dmp" or into the "%SystemRoot%\Minidump\" directory, and you can read it out with tools like guestfish(1). Memory dumps can be very large and Windows literally will not write them unless there's sufficient free disk space on C:. No space, no dump, no cap. ๐Ÿ˜ญ


๐Ÿš€ RUNNING A BATCH SCRIPT WHEN A USER LOGS IN ๐Ÿš€

Prepare a DOS batch script, VBScript or executable. Upload it using guestfish(1). For this example the script is called "test.bat" and it gets uploaded into "C:\":

guestfish -i -d WindowsGuest upload test.bat /test.bat

Now prep a regedit file containing the registry change:

cat > test.reg <<'EOF'
[HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce]
"Test"="c:\\test.bat"
EOF

In this example we use the key "RunOnce" which means the script will run precisely once when the first user logs in. If you want it to run every time a user logs in, swap "RunOnce" for "Run". That's it, that's the whole trick. ๐Ÿ’…

Now update the registry:

virt-win-reg --merge WindowsGuest test.reg

๐Ÿ‘‘ INSTALLING A SERVICE ๐Ÿ‘‘

This section assumes you're already familiar with Windows services, and that you either have a program which handles the Windows Service Control Protocol directly, or you want to run any program using a service wrapper like SrvAny or the free RHSrvAny. Main character energy required, bestie. โœจ

First, upload the program โ€” and optionally the service wrapper. In this case the test program is called "test.exe" and we're using the RHSrvAny wrapper:

guestfish -i -d WindowsGuest <<EOF
  upload rhsrvany.exe /rhsrvany.exe
  upload test.exe /test.exe
EOF

Now prepare a regedit file containing the registry changes. In this example, the first registry change is needed for the service itself or the service wrapper (if used). The second registry change is only needed because I'm using the RHSrvAny service wrapper.

cat > service.reg <<'EOF'
[HKLM\SYSTEM\ControlSet001\services\RHSrvAny]
"Type"=dword:00000010
"Start"=dword:00000002
"ErrorControl"=dword:00000001
"ImagePath"="c:\\rhsrvany.exe"
"DisplayName"="RHSrvAny"
"ObjectName"="NetworkService"

[HKLM\SYSTEM\ControlSet001\services\RHSrvAny\Parameters]
"CommandLine"="c:\\test.exe"
"PWD"="c:\\Temp"
EOF

Notes, because I love you and I want you to get this right ๐Ÿ’–:

  • For use of "ControlSet001" see the section above in this manual page. You may need to adjust this according to the control set that is in use by the guest.
  • "ObjectName" controls the privileges that the service will have. An alternative is "ObjectName"="LocalSystem" which would be the most privileged account. ๐Ÿ‘€ Big power, handle with care.
  • For the meaning of the magic numbers, see this Microsoft KB article: http://support.microsoft.com/kb/103000.

Now update the registry:

virt-win-reg --merge WindowsGuest service.reg

๐Ÿš SHELL QUOTING ๐Ÿš

Be careful when passing parameters containing "\" (backslash) in the shell โ€” the shell will absolutely try you. Usually you'll have to use 'single quotes' or double backslashes (but not both) to protect them from the shell. Pick one, not both, fr fr. ๐Ÿ™ˆ

Paths and value names are case-insensitive.


๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹

hivex(3), hivexsh(1), hivexregedit(1), guestfs(3), guestfish(1), virt-cat(1), virt-tail(1), Sys::Guestfs(3), Win::Hivex(3), Win::Hivex::Regedit(3), Sys::Virt(3), http://libguestfs.org/. Go read them, they're iconic. ๐Ÿ“š


๐ŸŒˆ AUTHOR ๐ŸŒˆ

Richard W.M. Jones http://people.redhat.com/~rjones/


Copyright (C) 2010 Red Hat Inc.


โญ LICENSE โญ

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


๐Ÿ’€ BUGS ๐Ÿ’€

To get a list of bugs against libguestfs, use this link: https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools

To report a new bug against libguestfs, use this link: https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools

When reporting a bug, please supply (this is the part where you don't be shy, give us everything ๐Ÿซถ):

  • The version of libguestfs.
  • Where you got libguestfs (eg. which Linux distro, compiled from source, etc)
  • Describe the bug accurately and give a way to reproduce it.
  • Run libguestfs-test-tool(1) and paste the complete, unedited output into the bug report. Complete and unedited, bestie โ€” no trimming, no editing, no "I cleaned it up a bit". ๐Ÿ˜ญ

And that's the whole page, mwah ๐Ÿ’‹ This little gem is from guestfs-tools-1.57.3, dated 2026-09-16, and it's virt-win-reg(1) โ€” go forth and edit those registries responsibly, queen. ๐Ÿ‘‘โœจ

๐Ÿ“ฆ where this page comes from