.\" Automatically generated by Podwrapper::Man 1.44.0 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "virt-win-reg 1" .TH virt-win-reg 1 "2021-01-05" "libguestfs-1.44.0" "Virtualization Support" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" virt\-win\-reg \- Export and merge Windows Registry entries from a Windows guest .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& virt\-win\-reg domname \*(AqHKLM\ePath\eTo\eSubkey\*(Aq \& \& virt\-win\-reg domname \*(AqHKLM\ePath\eTo\eSubkey\*(Aq name \& \& virt\-win\-reg domname \*(AqHKLM\ePath\eTo\eSubkey\*(Aq @ \& \& virt\-win\-reg \-\-merge domname [input.reg ...] \& \& virt\-win\-reg [\-\-options] disk.img ... # instead of domname .Ve .SH "WARNING" .IX Header "WARNING" You must \fInot\fR use \f(CW\*(C`virt\-win\-reg\*(C'\fR with the \fI\-\-merge\fR option on live virtual machines. If you do this, you \fIwill\fR get irreversible disk corruption in the \s-1VM.\s0 \f(CW\*(C`virt\-win\-reg\*(C'\fR tries to stop you from doing this, but doesn't catch all cases. .PP 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 \fI\-\-merge\fR option, make sure you have a reliable backup first. .SH "DESCRIPTION" .IX Header "DESCRIPTION" This program can export and merge Windows Registry entries from a Windows guest. .PP The first parameter is the libvirt guest name or the raw disk image of a Windows guest. .PP If \fI\-\-merge\fR is \fInot\fR specified, then the chosen registry key is displayed/exported (recursively). For example: .PP .Vb 1 \& $ virt\-win\-reg Windows7 \*(AqHKEY_LOCAL_MACHINE\eSOFTWARE\eMicrosoft\*(Aq .Ve .PP You can also display single values from within registry keys, for example: .PP .Vb 3 \& $ cvkey=\*(AqHKLM\eSOFTWARE\eMicrosoft\eWindows NT\eCurrentVersion\*(Aq \& $ virt\-win\-reg Windows7 $cvkey ProductName \& Windows 7 Enterprise .Ve .PP With \fI\-\-merge\fR, you can merge a textual regedit file into the Windows Registry: .PP .Vb 1 \& $ virt\-win\-reg \-\-merge Windows7 changes.reg .Ve .SS "\s-1NOTE\s0" .IX Subsection "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 \fBlibguestfs\fR\|(3) or \fBguestfish\fR\|(1) and access them locally, eg. using \fBhivex\fR\|(3), \&\fBhivexsh\fR\|(1) or \fBhivexregedit\fR\|(1). .SH "OPTIONS" .IX Header "OPTIONS" .IP "\fB\-\-help\fR" 4 .IX Item "--help" Display brief help. .IP "\fB\-\-version\fR" 4 .IX Item "--version" Display version number and exit. .IP "\fB\-\-debug\fR" 4 .IX Item "--debug" Enable debugging messages. .IP "\fB\-c \s-1URI\s0\fR" 4 .IX Item "-c URI" .PD 0 .IP "\fB\-\-connect \s-1URI\s0\fR" 4 .IX Item "--connect URI" .PD If using libvirt, connect to the given \fI\s-1URI\s0\fR. If omitted, then we connect to the default libvirt hypervisor. .Sp If you specify guest block devices directly, then libvirt is not used at all. .IP "\fB\-\-format\fR raw" 4 .IX Item "--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. .Sp 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. .Sp If working with untrusted raw-format guest disk images, you should ensure the format is always specified. .IP "\fB\-\-merge\fR" 4 .IX Item "--merge" In merge mode, this merges a textual regedit file into the Windows Registry of the virtual machine. If this flag is \fInot\fR given then virt-win-reg displays or exports Registry entries instead. .Sp Note that \fI\-\-merge\fR is \fIunsafe\fR to use on live virtual machines, and will result in disk corruption. However exporting (without this flag) is always safe. .IP "\fB\-\-encoding\fR UTF\-16LE|ASCII" 4 .IX Item "--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 \&\*(L"\s-1ENCODING STRINGS\*(R"\s0 in \fBWin::Hivex::Regedit\fR\|(3). .Sp The default is to use \s-1UTF\-16LE,\s0 which should work with recent versions of Windows. .IP "\fB\-\-unsafe\-printable\-strings\fR" 4 .IX Item "--unsafe-printable-strings" When exporting (only), assume strings are \s-1UTF\-16LE\s0 and print them as strings instead of hex sequences. Remove the final zero codepoint from strings if present. .Sp This is unsafe and does not preserve the fidelity of strings in the original Registry for various reasons: .RS 4 .IP "\(bu" 4 Assumes the original encoding is \s-1UTF\-16LE.\s0 \s-1ASCII\s0 strings and strings in other encodings will be corrupted by this transformation. .IP "\(bu" 4 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. .IP "\(bu" 4 Loses information about whether a zero codepoint followed the string in the Registry or not. .RE .RS 4 .Sp This all happens because the Registry itself contains no information about how strings are encoded (see \&\*(L"\s-1ENCODING STRINGS\*(R"\s0 in \fBWin::Hivex::Regedit\fR\|(3)). .Sp You should only use this option for quick hacking and debugging of the Registry contents, and \fInever\fR use it if the output is going to be passed into another program or stored in another Registry. .RE .SH "SUPPORTED SYSTEMS" .IX Header "SUPPORTED SYSTEMS" The program currently supports Windows NT-derived guests starting with Windows \s-1XP\s0 through to at least Windows 8. .PP The following Registry keys are supported: .ie n .IP """HKEY_LOCAL_MACHINE\eSAM""" 4 .el .IP "\f(CWHKEY_LOCAL_MACHINE\eSAM\fR" 4 .IX Item "HKEY_LOCAL_MACHINESAM" .PD 0 .ie n .IP """HKEY_LOCAL_MACHINE\eSECURITY""" 4 .el .IP "\f(CWHKEY_LOCAL_MACHINE\eSECURITY\fR" 4 .IX Item "HKEY_LOCAL_MACHINESECURITY" .ie n .IP """HKEY_LOCAL_MACHINE\eSOFTWARE""" 4 .el .IP "\f(CWHKEY_LOCAL_MACHINE\eSOFTWARE\fR" 4 .IX Item "HKEY_LOCAL_MACHINESOFTWARE" .ie n .IP """HKEY_LOCAL_MACHINE\eSYSTEM""" 4 .el .IP "\f(CWHKEY_LOCAL_MACHINE\eSYSTEM\fR" 4 .IX Item "HKEY_LOCAL_MACHINESYSTEM" .ie n .IP """HKEY_USERS\e.DEFAULT""" 4 .el .IP "\f(CWHKEY_USERS\e.DEFAULT\fR" 4 .IX Item "HKEY_USERS.DEFAULT" .ie n .IP """HKEY_USERS\e\fISID\fP""" 4 .el .IP "\f(CWHKEY_USERS\e\f(CISID\f(CW\fR" 4 .IX Item "HKEY_USERSSID" .PD where \fI\s-1SID\s0\fR is a Windows User \s-1SID\s0 (eg. \f(CW\*(C`S\-1\-5\-18\*(C'\fR). .ie n .IP """HKEY_USERS\e\fIusername\fP""" 4 .el .IP "\f(CWHKEY_USERS\e\f(CIusername\f(CW\fR" 4 .IX Item "HKEY_USERSusername" where \fIusername\fR is a local user name (this is a libguestfs extension). .PP You can use \f(CW\*(C`HKLM\*(C'\fR as a shorthand for \f(CW\*(C`HKEY_LOCAL_MACHINE\*(C'\fR, and \&\f(CW\*(C`HKU\*(C'\fR for \f(CW\*(C`HKEY_USERS\*(C'\fR. .PP The literal keys \f(CW\*(C`HKEY_USERS\e$SID\*(C'\fR and \f(CW\*(C`HKEY_CURRENT_USER\*(C'\fR are not supported (there is no \*(L"current user\*(R"). .SS "\s-1WINDOWS 8\s0" .IX Subsection "WINDOWS 8" Windows 8 \*(L"fast startup\*(R" can prevent virt-win-reg from being able to edit the Registry. See \&\*(L"\s-1WINDOWS HIBERNATION AND WINDOWS 8 FAST STARTUP\*(R"\s0 in \fBguestfs\fR\|(3). .SH "ENCODING" .IX Header "ENCODING" \&\f(CW\*(C`virt\-win\-reg\*(C'\fR expects that regedit files have already been reencoded in the local encoding. Usually on Linux hosts, this means \s-1UTF\-8\s0 with Unix-style line endings. Since Windows regedit files are often in \&\s-1UTF\-16LE\s0 with Windows-style line endings, you may need to reencode the whole file before or after processing. .PP To reencode a file from Windows format to Linux (before processing it with the \fI\-\-merge\fR option), you would do something like this: .PP .Vb 1 \& iconv \-f utf\-16le \-t utf\-8 < win.reg | dos2unix > linux.reg .Ve .PP To go in the opposite direction, after exporting and before sending the file to a Windows user, do something like this: .PP .Vb 1 \& unix2dos linux.reg | iconv \-f utf\-8 \-t utf\-16le > win.reg .Ve .PP For more information about encoding, see \fBWin::Hivex::Regedit\fR\|(3). .PP If you are unsure about the current encoding, use the \fBfile\fR\|(1) command. Recent versions of Windows regedit.exe produce a \s-1UTF\-16LE\s0 file with Windows-style (\s-1CRLF\s0) line endings, like this: .PP .Vb 3 \& $ file software.reg \& software.reg: Little\-endian UTF\-16 Unicode text, with very long lines, \& with CRLF line terminators .Ve .PP This file would need conversion before you could \fI\-\-merge\fR it. .SH "CurrentControlSet etc." .IX Header "CurrentControlSet etc." Registry keys like \f(CW\*(C`CurrentControlSet\*(C'\fR don’t really exist in the Windows Registry at the level of the hive file, and therefore you cannot modify these. .PP \&\f(CW\*(C`CurrentControlSet\*(C'\fR is usually an alias for \f(CW\*(C`ControlSet001\*(C'\fR. In some circumstances it might refer to another control set. The way to find out is to look at the \f(CW\*(C`HKLM\eSYSTEM\eSelect\*(C'\fR key: .PP .Vb 6 \& # virt\-win\-reg WindowsGuest \*(AqHKLM\eSYSTEM\eSelect\*(Aq \& [HKEY_LOCAL_MACHINE\eSYSTEM\eSelect] \& "Current"=dword:00000001 \& "Default"=dword:00000001 \& "Failed"=dword:00000000 \& "LastKnownGood"=dword:00000002 .Ve .PP \&\*(L"Current\*(R" is the one which Windows will choose when it boots. .PP Similarly, other \f(CW\*(C`Current...\*(C'\fR keys in the path may need to be replaced. .SH "DELETING REGISTRY KEYS AND VALUES" .IX Header "DELETING REGISTRY KEYS AND VALUES" To delete a whole registry key, use the syntax: .PP .Vb 1 \& [\-HKEY_LOCAL_MACHINE\eFoo] .Ve .PP To delete a single value within a key, use the syntax: .PP .Vb 2 \& [HKEY_LOCAL_MACHINE\eFoo] \& "Value"=\- .Ve .SH "WINDOWS TIPS" .IX Header "WINDOWS TIPS" Note that some of these tips modify the guest disk image. The guest \&\fImust\fR be shut off, else you will get disk corruption. .SS "\s-1RUNNING A BATCH SCRIPT WHEN A USER LOGS IN\s0" .IX Subsection "RUNNING A BATCH SCRIPT WHEN A USER LOGS IN" Prepare a \s-1DOS\s0 batch script, VBScript or executable. Upload this using \&\fBguestfish\fR\|(1). For this example the script is called \f(CW\*(C`test.bat\*(C'\fR and it is uploaded into \f(CW\*(C`C:\e\*(C'\fR: .PP .Vb 1 \& guestfish \-i \-d WindowsGuest upload test.bat /test.bat .Ve .PP Prepare a regedit file containing the registry change: .PP .Vb 4 \& cat > test.reg <<\*(AqEOF\*(Aq \& [HKLM\eSoftware\eMicrosoft\eWindows\eCurrentVersion\eRunOnce] \& "Test"="c:\e\etest.bat" \& EOF .Ve .PP In this example we use the key \f(CW\*(C`RunOnce\*(C'\fR which means that the script will run precisely once when the first user logs in. If you want it to run every time a user logs in, replace \f(CW\*(C`RunOnce\*(C'\fR with \f(CW\*(C`Run\*(C'\fR. .PP Now update the registry: .PP .Vb 1 \& virt\-win\-reg \-\-merge WindowsGuest test.reg .Ve .SS "\s-1INSTALLING A SERVICE\s0" .IX Subsection "INSTALLING A SERVICE" This section assumes you are familiar with Windows services, and 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. .PP First upload the program and optionally the service wrapper. In this case the test program is called \f(CW\*(C`test.exe\*(C'\fR and we are using the RHSrvAny wrapper: .PP .Vb 4 \& guestfish \-i \-d WindowsGuest < service.reg <<\*(AqEOF\*(Aq \& [HKLM\eSYSTEM\eControlSet001\eservices\eRHSrvAny] \& "Type"=dword:00000010 \& "Start"=dword:00000002 \& "ErrorControl"=dword:00000001 \& "ImagePath"="c:\e\erhsrvany.exe" \& "DisplayName"="RHSrvAny" \& "ObjectName"="NetworkService" \& \& [HKLM\eSYSTEM\eControlSet001\eservices\eRHSrvAny\eParameters] \& "CommandLine"="c:\e\etest.exe" \& "PWD"="c:\e\eTemp" \& EOF .Ve .PP Notes: .IP "\(bu" 4 For use of \f(CW\*(C`ControlSet001\*(C'\fR 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. .IP "\(bu" 4 \&\f(CW"ObjectName"\fR controls the privileges that the service will have. An alternative is \f(CW"ObjectName"="LocalSystem"\fR which would be the most privileged account. .IP "\(bu" 4 For the meaning of the magic numbers, see this Microsoft \s-1KB\s0 article: http://support.microsoft.com/kb/103000. .PP Update the registry: .PP .Vb 1 \& virt\-win\-reg \-\-merge WindowsGuest service.reg .Ve .SH "SHELL QUOTING" .IX Header "SHELL QUOTING" Be careful when passing parameters containing \f(CW\*(C`\e\*(C'\fR (backslash) in the shell. Usually you will have to use 'single quotes' or double backslashes (but not both) to protect them from the shell. .PP Paths and value names are case-insensitive. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBhivex\fR\|(3), \&\fBhivexsh\fR\|(1), \&\fBhivexregedit\fR\|(1), \&\fBguestfs\fR\|(3), \&\fBguestfish\fR\|(1), \&\fBvirt\-cat\fR\|(1), \&\fBvirt\-tail\fR\|(1), \&\fBSys::Guestfs\fR\|(3), \&\fBWin::Hivex\fR\|(3), \&\fBWin::Hivex::Regedit\fR\|(3), \&\fBSys::Virt\fR\|(3), http://libguestfs.org/. .SH "AUTHOR" .IX Header "AUTHOR" Richard W.M. Jones http://people.redhat.com/~rjones/ .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (C) 2010 Red Hat Inc. .SH "LICENSE" .IX Header "LICENSE" This program is free software; you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. .PP This program is distributed in the hope that it will be useful, but \&\s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of \&\s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE.\s0 See the \s-1GNU\s0 General Public License for more details. .PP You should have received a copy of the \s-1GNU\s0 General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, \s-1MA 02110\-1301 USA.\s0 .SH "BUGS" .IX Header "BUGS" To get a list of bugs against libguestfs, use this link: https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools .PP To report a new bug against libguestfs, use this link: https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools .PP When reporting a bug, please supply: .IP "\(bu" 4 The version of libguestfs. .IP "\(bu" 4 Where you got libguestfs (eg. which Linux distro, compiled from source, etc) .IP "\(bu" 4 Describe the bug accurately and give a way to reproduce it. .IP "\(bu" 4 Run \fBlibguestfs\-test\-tool\fR\|(1) and paste the \fBcomplete, unedited\fR output into the bug report.